vue3定义全局变量方法变更及$on废弃(Vue3 global variable definition method change and $on Abandonment)-vue
vue3定义全局变量方法变更及$on废弃(Vue3 global variable definition method change and $on Abandonment)
在vue2中,直接
Vue.prototype.$bus = new Vue()
但是在vue3中,方法改变了(因为$on方法的废弃,需要用到mitt)
const app = createApp(App)
app.config.globalProperties.$bus = new mitt();
app.use(store).use(router).mount('#app')
则使用$bus.emit去提交
然后使用$bus.on 去获取(没有$)
imageLoad() {
this.$bus.$emit('itemImageLoad')
},
this.$bus.on('itemImageLoad', () => {
refresh()
});
参考:https://blog.csdn.net/qq_39179734/article/details/120740618
————————
In vue2, direct
Vue.prototype.$bus = new Vue()
But in vue3, the method is changed (mitt is needed because of the abandonment of the $on method)
const app = createApp(App)
app.config.globalProperties.$bus = new mitt();
app.use(store).use(router).mount('#app')
Use $bus Emit to submit
Then use $bus On to get (no $)
imageLoad() {
this.$bus.$emit('itemImageLoad')
},
this.$bus.on('itemImageLoad', () => {
refresh()
});
参考:https://blog.csdn.net/qq_39179734/article/details/120740618