mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-04 12:17:37 +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)
|
|
},
|
|
}
|
|
}
|