watchOnce
用于使用 { once: true }
监视值的简写。回调函数触发一次后,侦听器将停止。有关完整详细信息,请参阅 Vue 的文档。
用法
类似于 watch
,但带有 { once: true }
ts
import { watchOnce } from '@vueuse/core'
watchOnce(source, () => {
// triggers only once
console.log('source changed!')
})
类型声明
ts
export declare function watchOnce<T extends Readonly<WatchSource<unknown>[]>>(
source: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, true>>,
options?: Omit<WatchOptions<true>, "once">,
): WatchHandle
export declare function watchOnce<T>(
source: WatchSource<T>,
cb: WatchCallback<T, T | undefined>,
options?: Omit<WatchOptions<true>, "once">,
): WatchHandle
export declare function watchOnce<T extends object>(
source: T,
cb: WatchCallback<T, T | undefined>,
options?: Omit<WatchOptions<true>, "once">,
): WatchHandle