Skip to content

watchAtMost

Category
Export Size
510 B
Last Changed
last month

watch 监听器带有触发次数限制。

使用方法

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

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

watchAtMost(
  source,
  () => { console.log('触发!') }, // 最多触发 3 次
  {
    count: 3, // 触发次数
  },
)

类型声明

typescript
export interface WatchAtMostOptions<Immediate>
  extends WatchWithFilterOptions<Immediate> {
  count: MaybeRefOrGetter<number>
}
export interface WatchAtMostReturn {
  stop: WatchStopHandle
  count: Ref<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

Source

SourceDocs

贡献者

Anthony Fu
丶远方
Anthony Fu
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

变更日志

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue

Released under the MIT License.