watchOnce
watch
that only triggers once.
Usage
After the callback function has been triggered once, the watch will be stopped automatically.
ts
import { watchOnce } from '@vueuse/core'
watchOnce(source, () => {
// triggers only once
console.log('source changed!')
})
import { watchOnce } from '@vueuse/core'
watchOnce(source, () => {
// triggers only once
console.log('source changed!')
})
Type Declarations
typescript
export declare function watchOnce<
T extends Readonly<WatchSource<unknown>[]>,
Immediate extends Readonly<boolean> = false
>(
source: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: WatchOptions<Immediate>
): void
export declare function watchOnce<
T,
Immediate extends Readonly<boolean> = false
>(
sources: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchOptions<Immediate>
): void
export declare function watchOnce<
T extends Readonly<WatchSource<unknown>[]>,
Immediate extends Readonly<boolean> = false
>(
source: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: WatchOptions<Immediate>
): void
export declare function watchOnce<
T,
Immediate extends Readonly<boolean> = false
>(
sources: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchOptions<Immediate>
): void
Source
Contributors
Anthony Fu
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz