Delay is set to 1000ms for this demo.

Input:

Times Updated: 0

debouncedWatch

Debounced watch

Usage

Similar to watch, but offering an extra option debounce which will be applied to the callback function.

import { debouncedWatch } from '@vueuse/core'

debouncedWatch(
  source,
  () => { console.log('changed!') },
  { debounce: 500 }
)

It's essentially a shorthand for the following code:

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

watchWithFilter(
  source,
  () => { console.log('changed!') },
  {
    eventFilter: debounceFilter(500),
  }
)

Type Declarations

export interface DebouncedWatchOptions<Immediate>
  extends WatchOptions<Immediate> {
  debounce?: MaybeRef<number>
}
export declare function debouncedWatch<
  T extends Readonly<WatchSource<unknown>[]>,
  Immediate extends Readonly<boolean> = false
>(
  sources: T,
  cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
  options?: DebouncedWatchOptions<Immediate>
): WatchStopHandle
export declare function debouncedWatch<
  T,
  Immediate extends Readonly<boolean> = false
>(
  source: WatchSource<T>,
  cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
  options?: DebouncedWatchOptions<Immediate>
): WatchStopHandle
export declare function debouncedWatch<
  T extends object,
  Immediate extends Readonly<boolean> = false
>(
  source: T,
  cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
  options?: DebouncedWatchOptions<Immediate>
): WatchStopHandle

Source

SourceDemoDocs