2021-07-06 07:49:49 +08:00
|
|
|
import { onBeforeUnmount } from 'vue'
|
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
import type { TimeoutHandle } from '@element-plus/utils/types'
|
|
|
|
|
2021-07-06 07:49:49 +08:00
|
|
|
export default function () {
|
2021-08-24 13:36:48 +08:00
|
|
|
let timeoutHandle: TimeoutHandle
|
2021-07-06 07:49:49 +08:00
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
clearTimeout(timeoutHandle)
|
|
|
|
})
|
|
|
|
|
|
|
|
return {
|
|
|
|
registerTimeout: (fn: (...args: any[]) => unknown, delay: number) => {
|
|
|
|
clearTimeout(timeoutHandle)
|
2021-08-24 13:36:48 +08:00
|
|
|
timeoutHandle = setTimeout(fn, delay) as any as TimeoutHandle
|
2021-07-06 07:49:49 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelTimeout: () => {
|
|
|
|
clearTimeout(timeoutHandle)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|