$bus.$emit、$on 用于非父子组件之间通信
1、首先,需要在main.js中注册
Vue.prototype.$bus = new Vue();
new Vue({
render: h => h(App),
router,
store
}).$mount('#app')
2、在需要发送信息的组件中,发送事件:
this.$bus.$emit("removeActive",params) //removeActive事件名,params传递的参数
3、在需要接收信息的组件中,接收参数:
this.$bus.$on("removeActive",(params)=>{
console.log('bbb',params);//处理传递过来的参数
})