Skip to content
On this page

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)
import { useTimeoutFn } from '@vueuse/core'

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

Type Declarations

typescript
export interface UseTimeoutFnOptions {
  /**
   * Start the timer immediate after calling this function
   *
   * @default true
   */
  immediate?: boolean
}
/**
 * Wrapper for `setTimeout` with controls.
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useTimeoutFn<
  CallbackFn extends (...args: any[]) => any
>(
  cb: CallbackFn,
  interval: MaybeComputedRef<number>,
  options?: UseTimeoutFnOptions
): Stoppable<Parameters<CallbackFn> | []>
export interface UseTimeoutFnOptions {
  /**
   * Start the timer immediate after calling this function
   *
   * @default true
   */
  immediate?: boolean
}
/**
 * Wrapper for `setTimeout` with controls.
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useTimeoutFn<
  CallbackFn extends (...args: any[]) => any
>(
  cb: CallbackFn,
  interval: MaybeComputedRef<number>,
  options?: UseTimeoutFnOptions
): Stoppable<Parameters<CallbackFn> | []>

Source

Category
Export Size
347 B
Last Changed
2 months ago

SourceDemoDocs

贡献者(Contributors)

日志(Changelog)

v9.12.0 on 2023/1/29
39183 - feat(useRafFn, useIntervalFn, useTimeoutFn): make status readonly (#2685)
e054a - fix: respect callback parameters in start function (#2693)

Released under the MIT License.