mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-27 03:01:14 +08:00
6b4c04fd0a
* feat(hooks): add use-timeout hook - Add use timeout hook for register timeout callbacks - Add test cases against add-timeout * resolve linter issue
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)
|
|
},
|
|
}
|
|
}
|