Skip to content

useTimeoutFn

Category
Export Size
303 B
Last Changed
15 minutes ago

带有控制选项的 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> | []>

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
Scott Bedard
Anthony Fu
童欧巴
Dan Rose
Kasper Seweryn
jack zhang
vaakian X
Jelf
Shinigami
Peter Shih
liaoliao666
Sergey Shumov

变更日志

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue
v9.12.0 on 1/29/2023
39183 - feat(useRafFn, useIntervalFn, useTimeoutFn): make status readonly (#2685)
e054a - fix: respect callback parameters in start function (#2693)

Released under the MIT License.