watchOnce
仅触发一次的 watch
。
使用方法
一旦回调函数被触发一次,监听将自动停止。
typescript
import { watchOnce } from '@vueuse/core'
watchOnce(source, () => {
// 仅触发一次
console.log('源发生变化!')
})
类型声明
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
Source
贡献者
Anthony Fu
丶远方
Anthony Fu
Valery
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz