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: 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
- feat(toValue): 弃用 @vueuse/shared
中的 toValue
,转而使用 Vue 原生类型v12.0.0-beta.1
于 2024/11/21v10.0.0-beta.4
于 2023/4/134d757
- feat(types)!: 将 MaybeComputedRef
重命名为 MaybeRefOrGetter
0a72b
- feat(toValue): 将 resolveUnref
重命名为 toValue