Skip to content

useInterval

反应式计数器在每个时间间隔都会增加

¥Reactive counter increases on every interval

示例

Interval fired: 0

用法

¥Usage

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

// count will increase every 200ms
const counter = useInterval(200)
ts
const { counter, reset, pause, resume } = useInterval(200, { controls: true })

类型声明

typescript
export interface UseIntervalOptions<Controls extends boolean> {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
  /**
   * Execute the update immediately on calling
   *
   * @default true
   */
  immediate?: boolean
  /**
   * Callback on every interval
   */
  callback?: (count: number) => void
}
export interface UseIntervalControls {
  counter: Ref<number>
  reset: () => void
}
/**
 * Reactive counter increases on every interval
 *
 * @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

源代码

源代码示例文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号