watchAtMost
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
源码
贡献者
Anthony Fu
一纸忘忧
Anthony Fu
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz
更新日志
v12.3.0
on 1/2/202559f75
- feat(toValue): deprecate toValue
from @vueuse/shared
in favor of Vue's nativev12.0.0-beta.1
on 11/21/2024v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue