mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-08-10 16:11:53 +08:00
初始化项目,自 v1.7.1 版本开始
This commit is contained in:
22
src/hooks/web/useEmitt.ts
Normal file
22
src/hooks/web/useEmitt.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user