Let's set the stage:
export default Vue.extend({
name: 'Home',
computed: {
...mapState('user', ['card']),
},
created() {
this.fetchData();
},
mounted() {
this.$once('dataLoaded', () => {
if (!this.card) {
this.showWarning();
}
});
},
watch: {
'$route': 'fetchData'
},
methods: {
async fetchData() {
await Promise.all([...]);
this.$emit('dataLoaded');
},
showWarning() {
// Vue global Plugin for creating a banner
Notify.create();
}
}
});
I placed the listener in the mounted
lifecycle, but I'm contemplating whether it should be in the created()
lifecycle instead. It seems to function properly in both instances, so I'm curious if there are any best practices I should follow or if I overlooked something crucial here.
Appreciate your insights!