コンテンツへスキップ

watchAtMost

カテゴリ
エクスポートサイズ
510 B
最終更新日
先週

トリガーされた回数を指定できる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: 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

ソースコード

ソースコードドキュメント

コントリビューター

Anthony Fu
Anthony Fu
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

変更ログ

v12.0.0-beta.1 2024/11/21
0a9ed - feat!: Vue 2サポートの削除、バンドルの最適化、クリーンアップ (#4349)
v10.0.0-beta.4 2023/04/13
4d757 - feat(types)!: MaybeComputedRefの名前をMaybeRefOrGetterに変更
0a72b - feat(toValue): resolveUnrefの名前をtoValueに変更

MITライセンスの下でリリースされています。