Skip to content

watchWithFilter

类别
导出体积
373 B
上次更改
2 weeks ago

带有额外 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

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
vaakian X
lvjiaxuan

更新日志

没有最近的更新日志