Skip to content

useTimeout

Category
Export Size
565 B
Last Changed
15 minutes ago

在一定时间后更新值,并带有控制功能。

Demo

准备就绪:false

使用方法

js
import { promiseTimeout, useTimeout } from '@vueuse/core'

const ready = useTimeout(1000)
js
const { ready, start, stop } = useTimeout(1000, { controls: true })
js
console.log(ready.value) // false

await promiseTimeout(1200)

console.log(ready.value) // true

类型声明

typescript
export interface UseTimeoutOptions<Controls extends boolean>
  extends UseTimeoutFnOptions {
  /**
   * 暴露更多控制选项
   *
   * @default false
   */
  controls?: Controls
  /**
   * 超时时的回调函数
   */
  callback?: Fn
}
/**
 * 在一定时间后更新值,并带有控制功能。
 *
 * @see   {@link https://vueuse.org/useTimeout}
 * @param interval
 * @param options
 */
export declare function useTimeout(
  interval?: MaybeRefOrGetter<number>,
  options?: UseTimeoutOptions<false>,
): ComputedRef<boolean>
export declare function useTimeout(
  interval: MaybeRefOrGetter<number>,
  options: UseTimeoutOptions<true>,
): {
  ready: ComputedRef<boolean>
} & Stoppable

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
Anthony Fu
huiliangShen
Waleed Khaled
vaakian X
Jelf
Shinigami
Mark Noonan

变更日志

v10.10.0 on 5/27/2024
4eede - feat: target support reactivity (#3923)

Released under the MIT License.