useTimeoutFn
带有控制选项的 setTimeout 函数的封装
Demo
Please wait for 3 seconds
用法
js
import { useTimeoutFn } from '@vueuse/core'
const { isPending, start, stop } = useTimeoutFn(() => {
/* ... */
}, 3000)
类型声明
typescript
export interface UseTimeoutFnOptions {
/**
* 在调用此函数后立即启动计时器
*
* @default true
*/
immediate?: boolean
}
/**
* 带有控制选项的 setTimeout 函数的封装
*
* @param cb 回调函数
* @param interval 延迟的时间(毫秒)
* @param options 可选参数
*/
export declare function useTimeoutFn<CallbackFn extends AnyFn>(
cb: CallbackFn,
interval: MaybeRefOrGetter<number>,
options?: UseTimeoutFnOptions,
): Stoppable<Parameters<CallbackFn> | []>