Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/watchPausable.md
1---2category: Watch3alias: pausableWatch4---56# watchPausable78Pausable watch910::: info11This function will be removed in future version.12:::1314::: tip1516[Pausable Watcher](https://vuejs.org/api/reactivity-core.html#watch) has been added to Vue [since 3.5](https://github.com/vuejs/core/pull/9651), use `const { stop, pause, resume } = watch(watchSource, callback)` instead.1718:::1920## Usage2122Use as normal the `watch`, but return extra `pause()` and `resume()` functions to control.2324```ts25import { watchPausable } from '@vueuse/core'26import { nextTick, shallowRef } from 'vue'2728const source = shallowRef('foo')2930const { stop, pause, resume } = watchPausable(31source,32v => console.log(`Changed to ${v}!`),33)3435source.value = 'bar'36await nextTick() // Changed to bar!3738pause()3940source.value = 'foobar'41await nextTick() // (nothing happend)4243resume()4445source.value = 'hello'46await nextTick() // Changed to hello!47```4849## Type Declarations5051```ts52export interface WatchPausableReturn extends Pausable {53stop: WatchStopHandle54}55export type WatchPausableOptions<Immediate> =56WatchWithFilterOptions<Immediate> & PausableFilterOptions57/** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */58export declare function watchPausable<59T extends Readonly<MultiWatchSources>,60Immediate extends Readonly<boolean> = false,61>(62sources: [...T],63cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,64options?: WatchPausableOptions<Immediate>,65): WatchPausableReturn66/** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */67export declare function watchPausable<68T,69Immediate extends Readonly<boolean> = false,70>(71source: WatchSource<T>,72cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,73options?: WatchPausableOptions<Immediate>,74): WatchPausableReturn75/** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */76export declare function watchPausable<77T extends object,78Immediate extends Readonly<boolean> = false,79>(80source: T,81cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,82options?: WatchPausableOptions<Immediate>,83): WatchPausableReturn84/** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */85export declare const pausableWatch: typeof watchPausable86```87