//common.vue
this.$bus.emit('msg',data)
//a.vue
created(){
this.$bus.on('msg', params => {})
},
beforeDestroy(){
this.$bus.$off('msg')
}
//b.vue
created(){
this.$bus.on('msg', params => {})
},
beforeDestroy(){
this.$bus.$off('msg')
}
a组件和b组件都调用了公用组件common.vue,a组件销毁前清除了bus,a页面跳转到b页面后,导致接收不到bus的通信了
请问应该怎么解决,不清除会反复接受到数据
A跳到B
先触发B created,再出发A destroy.
你应该给事件函数加一个名字(可以放到methods里) off的时候仅删除该函数。