主题
watchOnce
watch
仅触发一次。
¥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!')
})
类型声明
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>,
): WatchStopHandle
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>,
): WatchStopHandle