@pangtou/mitt
v1.0.4
Published
事件的订阅与发布
Downloads
12
Readme
PTAdmin 插件库
介绍
基于 https://github.com/developit/mitt 做的修改
安装方式
# npm
npm install @pangtou/mitt
# yarn
yarn install @pangtou/mitt
# pnpm
pnpm add @pangtou/mitt
- UMD 构建 unpkg 使用
<script src="https://unpkg.com/@pangtou/mitt/dist/pangtou.mitt.umd.cjs"></script>
使用方法
import mitt from '@pangtou/mitt';
type Events = {
foo: string;
bar?: number;
};
const emit = mitt<Events>();
// 定义监听事件
emit.on('foo', (e) => {});
// 执行事件
emit.emit('foo', 42);