Skip to content

useTimeoutFn

Category
Export Size
321 B
Last Changed
last month

带有控制选项的 setTimeout 函数的封装

Demo

Please wait for 3 seconds

用法

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

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

Type Declarations

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> | []>

Source

SourceDemoDocs

Contributors

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

Changelog

7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
64c53 - feat(useTimtoutFn,useTimeoutPoll): align behavior (#4543)
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue

Released under the MIT License.