跳到内容

useIntervalFn

类别
导出大小
368 B
最后更改
5 天前

setInterval 的带控件的包装器

演示

你好

间隔

用法

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

const { pause, resume, isActive } = useIntervalFn(() => {
  /* your function */
}, 1000)

类型声明

typescript
export interface UseIntervalFnOptions {
  /**
   * Start the timer immediately
   *
   * @default true
   */
  immediate?: boolean
  /**
   * Execute the callback immediately after calling `resume`
   *
   * @default false
   */
  immediateCallback?: boolean
}
/**
 * Wrapper for `setInterval` with controls
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useIntervalFn(
  cb: Fn,
  interval?: MaybeRefOrGetter<number>,
  options?: UseIntervalFnOptions,
): Pausable

源代码

源代码演示文档

贡献者

Anthony Fu
Anthony Fu
Jelf
IlyaL
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.8.0 于 2025/3/5
7432f - feat(types): 弃用 MaybeRefMaybeRefOrGetter,支持 Vue 的原生类型 (#4636)
v12.3.0 于 2025/1/2
59f75 - feat(toValue): 弃用来自 @vueuse/sharedtoValue,支持 Vue 的原生类型
v12.0.0-beta.1 于 2024/11/21
0a9ed - feat!: 移除 Vue 2 支持,优化包并清理 (#4349)
v11.2.0 于 2024/10/30
59f8c - fix: 阻止在 cb 中调用 pause 后设置定时器 (#4258)
v10.0.0-beta.5 于 2023/4/13
cb644 - refactor!: 移除 isFunctionisString 工具函数
v10.0.0-beta.4 于 2023/4/13
4d757 - feat(types)!: 将 MaybeComputedRef 重命名为 MaybeRefOrGetter
0a72b - feat(toValue): 将 resolveUnref 重命名为 toValue
v9.12.0 于 2023/1/29
39183 - feat(useRafFn, useIntervalFn, useTimeoutFn): 使状态变为只读 (#2685)

根据 MIT 许可证发布。