Skip to content

useIntervalFn

Category
Export Size
341 B
Last Changed
15 minutes ago

带有控制功能的 setInterval 包装器

Demo

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

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
Jelf
Lapor Chen
Anthony Fu
Börge Kiss
Dan Rose
sun0day
Enzo Innocenzi
wwj
Matvey Melishev
meteorlxy
Aurélio A. Heckert
xuxuhahaha
Hogne Vevle
Daiki Ojima

变更日志

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)
v9.7.0 on 12/16/2022
8bb7b - fix: watch computed refs instead of just refs (#2539)

Released under the MIT License.