Skip to content

useIntervalFn

类别
导出体积
368 B
上次更改
3 weeks ago

带有控制功能的 setInterval 包装器

示例

Hello

间隔:

使用方法

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

const { pause, resume, isActive } = useIntervalFn(() => {
  /* 你的函数 */
}, 1000)

类型声明

typescript
export interface UseIntervalFnOptions {
  /**
   * 立即开始计时器
   *
   * @default true
   */
  immediate?: boolean
  /**
   * 在调用 `resume` 之后立即执行回调
   *
   * @default false
   */
  immediateCallback?: boolean
}
/**
 * 带有控制功能的 `setInterval` 包装器
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useIntervalFn(
  cb: Fn,
  interval?: MaybeRefOrGetter<number>,
  options?: UseIntervalFnOptions,
): Pausable

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
Jelf
OrbisK
Lapor Chen
Börge Kiss
Dan Rose
sun0day
Enzo Innocenzi
wwj
Matvey Melishev
meteorlxy
Aurélio A. Heckert
xuxuhahaha
Hogne Vevle
Daiki Ojima

更新日志

v12.3.0 on 1/2/2025
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v11.2.0 on 10/30/2024
59f8c - fix: prevent timer being set after pause is called in cb (#4258)
v10.0.0-beta.5 on 4/13/2023
cb644 - refactor!: remove isFunction and isString utils
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)