const PubSub = {
message: {},
//发布者
publish(type) {
if (!this.message[type]) return;
this.message[type].foreach((item) => item);
},
// 订阅者
subscribe(type, cb) {
if (!this.message[type]) {
this.message[type] = [cb];
} else {
this.message[type].push();
}
},
};
02-21
252
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-06
504
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-01
515
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)