https://github.com/markthree/tob-mitt
mitt 的 uni_modules 完美迁移版本
https://github.com/markthree/tob-mitt
mitt tob uniapp vue3
Last synced: about 1 year ago
JSON representation
mitt 的 uni_modules 完美迁移版本
- Host: GitHub
- URL: https://github.com/markthree/tob-mitt
- Owner: markthree
- License: mit
- Created: 2022-01-24T14:55:29.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-02-28T08:49:50.000Z (about 2 years ago)
- Last Synced: 2024-04-29T21:11:28.159Z (almost 2 years ago)
- Topics: mitt, tob, uniapp, vue3
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# tob-mitt
在 `vue3` 中,[mitt](https://github.com/developit/mitt) 是一个推荐的 `eventBus` 库。这是一个 `uni_modules` 的完美迁移版本。
## 原仓库 📦
👉 [mitt](https://github.com/developit/mitt)
## Usage 🦖
```js
import mitt from "@/uni_modules/tob-mitt/index.js"
const bus = mitt()
// 注册两个指定类型的事件函数
bus.on('foo', () => console.log('我是foo1'))
bus.on('foo', () => console.log('我是foo2'))
// 触发该类型的事件函数
bus.emit('foo') // 将打印 我是foo1,我是foo2
// 注册一个带形参的事件函数
bus.on('bar', (msg) => console.log(msg))
// 触发事件函数的同时设置实参
bus.emit('bar', '你好') // 将打印 你好
bus.off('bar') // 卸载所有 bar 事件函数
const bar = () => console.log('我好')
bus.on('bar', bar)
bus.off('bar', bar) // 单独卸载该事件函数
bus.emit('bar') // 因为被卸载了,所以什么都不会触发
// 注册所有类型的事件函数
bus.on('*', () => {
console.log("不论什么时候都会触发")
})
// 触发 * 类型的事件函数
bus.emit() // 打印 不论什么时候都会触发
bus.emit('foo') // 打印 我是foo1,我是foo2 不论什么时候都会触发
bus.all // 保存事件函数的 map
```
## 组织 🦔
欢迎关注 **帝莎编程**
- [官网](http://dishaxy.dishait.cn/)
- [Gitee](https://gitee.com/dishait)
- [Github](https://github.com/dishait)
- [网易云课堂](https://study.163.com/provider/480000001892585/index.htm?share=2&shareId=480000001892585)
## License
Made with markthree
Published under [MIT License](./LICENSE).