跳到内容

watchAtMost

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

watch,带有触发次数限制。

用法

类似于 watch,但增加了一个额外的选项 count,用于设置回调函数被触发的次数。达到次数后,watch 将自动停止。

ts
import { watchAtMost } from '@vueuse/core'

watchAtMost(
  source,
  () => { console.log('trigger!') }, // triggered it at most 3 times
  {
    count: 3, // the number of times triggered
  },
)

类型声明

typescript
export interface WatchAtMostOptions<Immediate>
  extends WatchWithFilterOptions<Immediate> {
  count: MaybeRefOrGetter<number>
}
export interface WatchAtMostReturn {
  stop: WatchStopHandle
  count: ShallowRef<number>
}
export declare function watchAtMost<
  T extends Readonly<WatchSource<unknown>[]>,
  Immediate extends Readonly<boolean> = false,
>(
  sources: [...T],
  cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
  options: WatchAtMostOptions<Immediate>,
): WatchAtMostReturn
export declare function watchAtMost<
  T,
  Immediate extends Readonly<boolean> = false,
>(
  sources: WatchSource<T>,
  cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
  options: WatchAtMostOptions<Immediate>,
): WatchAtMostReturn

来源

源码文档

贡献者

Anthony Fu
Anthony Fu
IlyaL
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

更新日志

v12.8.0 于 2025/3/5
7432f - feat(types): 弃用 MaybeRefMaybeRefOrGetter,转而使用 Vue 原生类型 (#4636)
v12.3.0 于 2025/1/2
59f75 - feat(toValue): 弃用 @vueuse/shared 中的 toValue,转而使用 Vue 原生类型
v12.0.0-beta.1 于 2024/11/21
0a9ed - feat!: 移除 Vue 2 支持,优化 bundles 并清理代码 (#4349)
v10.0.0-beta.4 于 2023/4/13
4d757 - feat(types)!: 将 MaybeComputedRef 重命名为 MaybeRefOrGetter
0a72b - feat(toValue): 将 resolveUnref 重命名为 toValue

根据 MIT 许可证发布。