watchAtMost
watch
搭配觸發次數。
用法
類似於 watch
,具有額外選項 count
,用於設定回呼函式觸發的次數。達到次數後,偵聽將自動停止。
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
原始碼
貢獻者
更新日誌
v12.8.0
於 2025/3/5v12.3.0
於 2025/1/259f75
- 特性(toValue): 棄用 toValue
,改用 Vue 原生v12.0.0-beta.1
於 2024/11/21v10.0.0-beta.4
於 2023/4/134d757
- 特性(types)!: 重新命名 MaybeComputedRef
為 MaybeRefOrGetter
0a72b
- 特性(toValue): 重新命名 resolveUnref
為 toValue