Skip to content

watchWithFilter

Category
Export Size
233 B
Last Changed
3 hours ago

带有额外 EventFilter 控制的 watch

用法

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

ts
import { debounceFilter, watchWithFilter } from '@vueuse/core'

watchWithFilter(
  source,
  () => { console.log('changed!') }, // 回调函数将以 500ms 的防抖方式被调用
  {
    eventFilter: debounceFilter(500), // throttledFilter、pausableFilter 或自定义过滤器
  },
)

Type Declarations

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

SourceDocs

Contributors

jorshen

Changelog

No recent changes

Released under the MIT License.