@retailwe/common-libs-event
v0.0.4
Published
RetailWe libs
Downloads
7
Readme
Event 事件订阅
安装
yarn add '@retailwe/common-libs-event' --save-exact
使用
import Event from '@retailwe/common-libs-event';
const event = new Event();
const callback = (msg) => {...};
// 监听
event.on('event_name', callback);
// 监听一次
event.once('event_name', callback);
// 触发
event.emit('event_name', msg);
// 移除指定事件的特定监听器
event.off('event_name', callback);
// 移除指定事件的所有监听器
event.offAll('event_name');