mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-24 11:05:17 +08:00
21 lines
430 B
TypeScript
21 lines
430 B
TypeScript
|
import { onBeforeUnmount } from 'vue'
|
||
|
|
||
|
export default function () {
|
||
|
let timeoutHandle: ReturnType<typeof setTimeout>
|
||
|
|
||
|
onBeforeUnmount(() => {
|
||
|
clearTimeout(timeoutHandle)
|
||
|
})
|
||
|
|
||
|
return {
|
||
|
registerTimeout: (fn: (...args: any[]) => unknown, delay: number) => {
|
||
|
clearTimeout(timeoutHandle)
|
||
|
timeoutHandle = setTimeout(fn, delay)
|
||
|
},
|
||
|
|
||
|
cancelTimeout: () => {
|
||
|
clearTimeout(timeoutHandle)
|
||
|
},
|
||
|
}
|
||
|
}
|