watchAtMost
トリガーされた回数を指定できる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
ソースコード
コントリビューター
変更ログ
v12.0.0-beta.1
2024/11/21v10.0.0-beta.4
2023/04/134d757
- feat(types)!: MaybeComputedRef
の名前をMaybeRefOrGetter
に変更0a72b
- feat(toValue): resolveUnref
の名前をtoValue
に変更