Skip to content

watchOnce

Category
Export Size
107 B
Last Changed
last month

仅触发一次的 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

SourceDocs

贡献者

Anthony Fu
丶远方
Anthony Fu
Valery
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

变更日志

v10.6.0 on 11/9/2023
bb0a7 - feat: return function for manual watcher stopping (#3475)

Released under the MIT License.