watchWithFilter
带有额外 EventFilter 控制的 watch
。
用法
类似于 watch
,但提供了额外选项 eventFilter
,该选项将应用于回调函数。
ts
import { debounceFilter, watchWithFilter } from '@vueuse/core'
watchWithFilter(
source,
() => { console.log('changed!') }, // 回调函数将以 500ms 的防抖方式调用
{
eventFilter: debounceFilter(500), // throttledFilter、pausabledFilter 或自定义过滤器
},
)
类型声明
typescript
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>,
): WatchStopHandle
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>,
): WatchStopHandle
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>,
): WatchStopHandle
Source
贡献者
Anthony Fu
丶远方
Anthony Fu
vaakian X
lvjiaxuan