vue中$bus.$emit和$bus.$on的用法温故
$bus. $emit、 $bus. $on 用于非父子组件之间通信
1、在main.js中注册
Vue.prototype.$bus = new Vue();new Vue({render: h => h(App),router,store
}).$mount('#app')
2、在需要发送信息的组件中,发送事件
this.$bus.$emit("method",params); //method事件名,params传递的参数
3、在需要接收信息的组件中,接收参数
this.$bus.$on("method",(params)=>{console.log('监听的method事件的参数值为:',params);//处理传递过来的参数});
可以与https://blog.csdn.net/leijie0322/article/details/128210817对比的看。