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