派发事件
add (form) {
this.EventBus.$on('addSuccess', form);
}
mounted() {
this.EventBus.$on('event', (form) => {
console.log(form);
});
},
beforeDestroy() {
this.EventBus.$off('event');
}
注意: this.EventBus.
o
f
f
(
′
e
v
e
n
t
′
)
;
不
能
传
参
数
,
t
h
i
s
.
E
v
e
n
t
B
u
s
.
off('event');不能传参数,this.EventBus.
off(′event′);不能传参数,this.EventBus.off(‘event’, {});
是不行的
大家谨慎使用EventBus,如果事件车变多会导致方法名不够用哈,另外一定要在绑定的页面进行off卸载