2021-05-09
// 事件派发 监听和回调管理
class Bus {
constructor() {
this.callbacks = {}
}
$on (name, fn) {
this.callbacks[name] = this.callbacks[name] || []
this.callbacks[name].push(fn)
}
$emit (name, args) {
if (this.callbacks[name]) {
this.callbacks[name].forEach(cb => cb(a
原创
2021-05-09 11:19:50 ·
57 阅读 ·
0 评论