Files
td_official/src/utils/bus.ts
2025-05-21 11:24:53 +08:00

23 lines
497 B
TypeScript

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);
};
};
}
};