Skip to content

Instantly share code, notes, and snippets.

@yogithesymbian
Last active August 6, 2023 03:45
Show Gist options
  • Save yogithesymbian/cff0238c47f37a9c30281dc513880886 to your computer and use it in GitHub Desktop.
Save yogithesymbian/cff0238c47f37a9c30281dc513880886 to your computer and use it in GitHub Desktop.
vue composition-api life hack
import useAppConfig from '@core/app-config/useAppConfig'
....
....
setup() { // defined
const { anIncomingNotification } = useAppConfig()
return {
anIncomingNotification
}
},
this.anIncomingNotification = payload // trigger watch
watch: {
anIncomingNotification() {
console.log('an incoming mesage key : ', this.anIncomingNotification) // print : payload
},
}
//PATH: /Users/yogiarifwidodo/Sites/X/X/src/@core/app-config/useAppConfig.js
import { computed, watch } from '@vue/composition-api'
import store from '@/store'
export default function usAppConfig() {
// ------------------------------------------------
// otherAPP
// ------------------------------------------------
// ------------------------------------------------
// error Handling
// ------------------------------------------------
const lookWatchException = computed({
get: () => store.state.app.watchException,
set: (val) => {
store.commit('app/WATCH_EXCEPTION', val)
}
})
const anIncomingNotification = computed({
get: () => store.state.app.watchNotification,
set: (val) => {
val += 1 /* re-rendering | :KEY | watch: {} */
store.commit('app/UPDATE_WATCH_NOTIFICATION', val)
}
})
return {
anIncomingNotification,
lookWatchException
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment