[add] 同步前端代码
This commit is contained in:
22
plus-ui/src/utils/bus.ts
Normal file
22
plus-ui/src/utils/bus.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import mitt from 'mitt';
|
||||
|
||||
const emitter = mitt();
|
||||
|
||||
export default {
|
||||
install(app) {
|
||||
// 发送事件
|
||||
app.config.globalProperties.$sendChanel = (event, payload) => {
|
||||
emitter.emit(event, payload);
|
||||
};
|
||||
|
||||
// 监听事件(返回取消函数)
|
||||
app.config.globalProperties.$recvChanel = (event, handler) => {
|
||||
emitter.on(event, handler);
|
||||
|
||||
// 可选:返回解绑函数,方便使用
|
||||
return () => {
|
||||
emitter.off(event, handler);
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user