跳到主要内容

watchWithFilter

分类
导出大小
233 B
上次更改
上个月

带有额外 EventFilter 控制的 watch

用法

类似于 watch,但提供一个额外的选项 eventFilter,它将被应用于回调函数。

ts
import { 
debounceFilter
,
watchWithFilter
} from '@vueuse/core'
watchWithFilter
(
source, () => {
console
.
log
('changed!') }, // callback will be called in 500ms debounced manner
{
eventFilter
:
debounceFilter
(500), // throttledFilter, pausableFilter or custom filters
}, )

类型声明

ts
export interface 
WatchWithFilterOptions
<
Immediate
>
extends WatchOptions<
Immediate
>,
ConfigurableEventFilter {} export declare function
watchWithFilter
<
T
extends
Readonly
<
WatchSource
<unknown>[]>,
Immediate
extends
Readonly
<boolean> = false,
>(
sources
: [...
T
],
cb
:
WatchCallback
<
MapSources
<
T
>,
MapOldSources
<
T
,
Immediate
>>,
options
?:
WatchWithFilterOptions
<
Immediate
>,
):
WatchHandle
export declare function
watchWithFilter
<
T
,
Immediate
extends
Readonly
<boolean> = false,
>(
source
:
WatchSource
<
T
>,
cb
:
WatchCallback
<
T
,
Immediate
extends true ?
T
| undefined :
T
>,
options
?:
WatchWithFilterOptions
<
Immediate
>,
):
WatchHandle
export declare function
watchWithFilter
<
T
extends object,
Immediate
extends
Readonly
<boolean> = false,
>(
source
:
T
,
cb
:
WatchCallback
<
T
,
Immediate
extends true ?
T
| undefined :
T
>,
options
?:
WatchWithFilterOptions
<
Immediate
>,
):
WatchHandle

来源

源码文档

贡献者

Anthony Fu
Arthur Darkstone
briwa
Anthony Fu
vaakian X
lvjiaxuan

更新日志

b8102 - feat(watch): 更新 watchExtractedObservable, watchDebounced, watchDeep, watchImmediate, watchOnce, watchThrottled 和 watchWithFilter 中 watch 返回值的类型错误 (#4896)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)

根据 MIT 许可证发布。