Files
orion-visor/orion-visor-ui/src/hooks/emitter.ts
lijiahangmax d3a045ec20 🔖 项目重命名.
2024-05-16 00:03:30 +08:00

27 lines
506 B
TypeScript

const emitter = 'emitter';
export default function useEmitter(emits: any) {
// 事件向上冒泡
const bubblesEmitter = (event: string, ...args: any[]) => {
if (args) {
emits(emitter, event, ...args);
} else {
emits(emitter, event);
}
};
// 处理冒泡事件
const dispatchEmitter = (event: string, ...args: any[]) => {
if (args) {
emits(event, ...args);
} else {
emits(event);
}
};
return {
bubblesEmitter,
dispatchEmitter
};
}