代码
class Bus {
eventList: any;
constructor() {
this.eventList = {};
}
$on(name: any, fn: any) {
this.eventList[name] = this.eventList[name] || [];
this.eventList[name].push(fn);
}
$emit(name: any, data: any) {
if (this.eventList[name]) {
this.eventList[name].forEach((fn: any) => {
fn(data);
});
}
}
$off(name: any) {
if (this.eventList[name]) {
delete this.eventList[name];
}
}
}
export default new Bus();
使用方法
Bus.$on('changWs', async () => {
postGetMissionBhLogFn();
})
Bus.$off('changWs');