Tiny 200b functional event emitter / pubsub.
文档
安装
npm install --save mitt
- 1
cdn
<script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>
- 1
使用示例
import mitt from 'mitt' const emitter = mitt() function onFoo(data) { console.log(data); } const TOPIC = 'topic' // 订阅 emitter.on(TOPIC, onFoo) // 发布事件 emitter.emit(TOPIC, { a: 'b' }) // 取消订阅 emitter.off(TOPIC, onFoo)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
原文链接:pengshiyu.blog.csdn.net/article/details/125961047