You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
336 B
23 lines
336 B
1 year ago
|
import mitt from 'mitt'
|
||
|
|
||
|
interface Option {
|
||
|
name: string // 事件名称
|
||
|
callback: Fn // 回调
|
||
|
}
|
||
|
|
||
|
const emitter = mitt()
|
||
|
|
||
|
export const useEmitt = (option?: Option) => {
|
||
|
if (option) {
|
||
|
emitter.on(option.name, option.callback)
|
||
|
|
||
|
onBeforeUnmount(() => {
|
||
|
emitter.off(option.name)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
emitter
|
||
|
}
|
||
|
}
|