Skip to content

useTimeoutFn

带控件的 setTimeout 封装。

¥Wrapper for setTimeout with controls.

示例

Please wait for 3 seconds

用法

¥Usage

js
import { useTimeoutFn } from '@vueuse/core'

const { isPending, start, stop } = useTimeoutFn(() => {
  /* ... */
}, 3000)

类型声明

typescript
export interface UseTimeoutFnOptions {
  /**
   * Start the timer immediately
   *
   * @default true
   */
  immediate?: boolean
  /**
   * Execute the callback immediately after calling `start`
   *
   * @default false
   */
  immediateCallback?: boolean
}
/**
 * Wrapper for `setTimeout` with controls.
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useTimeoutFn<CallbackFn extends AnyFn>(
  cb: CallbackFn,
  interval: MaybeRefOrGetter<number>,
  options?: UseTimeoutFnOptions,
): Stoppable<Parameters<CallbackFn> | []>

源代码

源代码示例文档

变更日志

v12.6.0 on 2/14/2025
64c53 - feat(useTimtoutFn,useTimeoutPoll): align behavior (#4543)

VueUse v12.7 中文网 - 粤ICP备13048890号