vue项目全局事件总线

步骤一:main.js  

new Vue({

 

beforeCreated(){

//全局事件总监

Vue.prototype.$bus = this

}

})

 

//监听地方回调

this.$bus.$on('监听的名字',(data) => {

//这里是获取到监听数据

})

页面卸载的时候使用$off

this.$bus.$off('监听的名字')

 

 

this.$bus.$emit('事件的名字',传递的数据)

 

posted @ 2023-02-21 22:47  爱尚丽明  阅读(4)  评论(0编辑  收藏  举报