mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-27 03:01:14 +08:00
23 lines
502 B
TypeScript
23 lines
502 B
TypeScript
import { onBeforeUnmount } from 'vue'
|
|
|
|
import type { TimeoutHandle } from '@element-plus/utils/types'
|
|
|
|
export default function () {
|
|
let timeoutHandle: TimeoutHandle
|
|
|
|
onBeforeUnmount(() => {
|
|
clearTimeout(timeoutHandle)
|
|
})
|
|
|
|
return {
|
|
registerTimeout: (fn: (...args: any[]) => unknown, delay: number) => {
|
|
clearTimeout(timeoutHandle)
|
|
timeoutHandle = setTimeout(fn, delay) as any as TimeoutHandle
|
|
},
|
|
|
|
cancelTimeout: () => {
|
|
clearTimeout(timeoutHandle)
|
|
},
|
|
}
|
|
}
|