Last active
August 6, 2023 03:45
-
-
Save yogithesymbian/cff0238c47f37a9c30281dc513880886 to your computer and use it in GitHub Desktop.
vue composition-api life hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useAppConfig from '@core/app-config/useAppConfig' | |
.... | |
.... | |
setup() { // defined | |
const { anIncomingNotification } = useAppConfig() | |
return { | |
anIncomingNotification | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.anIncomingNotification = payload // trigger watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
watch: { | |
anIncomingNotification() { | |
console.log('an incoming mesage key : ', this.anIncomingNotification) // print : payload | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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