Skip to content

watchAtMost

类别
导出体积
323 B
上次更改
2 days ago

watch 监听器带有触发次数限制。

使用方法

类似于 watch,但多了一个选项 count,用于设置回调函数触发的次数。达到次数后,监听将自动停止。

ts
import { 
watchAtMost
} from '@vueuse/core'
watchAtMost
(
source, () => {
console
.
log
('触发!') }, // 最多触发 3 次
{
count
: 3, // 触发次数
}, )

类型声明

ts
export interface 
WatchAtMostOptions
<
Immediate
>
extends WatchWithFilterOptions<
Immediate
> {
count
:
MaybeRefOrGetter
<number>
} export interface WatchAtMostReturn {
stop
:
WatchStopHandle
pause
: () => void
resume
: () => void
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

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
IlyaL
Arthur Darkstone
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

更新日志

d3176 - feat: add pause and resume to return value (#4897)
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)