mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-26 00:26:20 +08:00
initial commit
This commit is contained in:
23
src/hooks/core/useTimeout.ts
Normal file
23
src/hooks/core/useTimeout.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { TimeoutFnResult, Fn } from './types';
|
||||
|
||||
import { isFunction } from '/@/utils/is';
|
||||
import { watch } from 'vue';
|
||||
|
||||
import { useTimeoutRef } from '/@/hooks/core/useTimeoutRef';
|
||||
|
||||
export function useTimeout(handle: Fn<any>, wait: number): TimeoutFnResult {
|
||||
if (!isFunction(handle)) {
|
||||
throw new Error('handle is not Function!');
|
||||
}
|
||||
|
||||
const [readyRef, clear, runAgain] = useTimeoutRef(wait);
|
||||
|
||||
watch(
|
||||
readyRef,
|
||||
(maturity) => {
|
||||
maturity && handle();
|
||||
},
|
||||
{ immediate: false }
|
||||
);
|
||||
return [clear, runAgain, readyRef];
|
||||
}
|
Reference in New Issue
Block a user