事件总线的使用
在main.js中注册总线
Vue.prototype.$eventBus = new Vue();
注册
this.$eventBus.$emit('statistical','Signed');
使用: 在created中
this.$eventBus.$on('statistical', (type) => { // 注意这里面的type可以传多个参数
if (type == 'Customer') {
// 统计接口
this.getStatistics();
// tab统计的接口
this.getTabStatistics();
} else {
this.getTabStatistics();
}
})
销毁
beforeDestroy() {
this.$eventBus.$off('statistical')
},