Skip to content

useInterval

Category
Export Size
620 B
Last Changed
15 minutes ago

在每个间隔上增加的响应式计数器

Demo

间隔: 0

使用方法

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

// 每200ms计数增加一次
const counter = useInterval(200)
ts
const { counter, reset, pause, resume } = useInterval(200, { controls: true })

类型声明

typescript
export interface UseIntervalOptions<Controls extends boolean> {
  /**
   * 暴露更多控制选项
   *
   * @default false
   */
  controls?: Controls
  /**
   * 在调用时立即执行更新
   *
   * @default true
   */
  immediate?: boolean
  /**
   * 每个间隔上的回调函数
   */
  callback?: (count: number) => void
}
export interface UseIntervalControls {
  counter: Ref<number>
  reset: () => void
}
/**
 * 每个间隔上增加的响应式计数器
 *
 * @see https://vueuse.org/useInterval
 * @param interval
 * @param options
 */
export declare function useInterval(
  interval?: MaybeRefOrGetter<number>,
  options?: UseIntervalOptions<false>,
): Ref<number>
export declare function useInterval(
  interval: MaybeRefOrGetter<number>,
  options: UseIntervalOptions<true>,
): UseIntervalControls & Pausable

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
Jelf
Anthony Fu
mohammadhosry
Waleed Khaled
vaakian X
Nurettin Kaya

变更日志

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
v9.13.0 on 2/18/2023
db66c - fix: fix types
81db6 - feat: add reset function (#2686)

Released under the MIT License.