Skip to content

watchOnce

Category
Export Size
140 B
Last Changed
3 hours ago

仅触发一次的 watch

使用方法

一旦回调函数被触发一次,监听将自动停止。

typescript
import { watchOnce } from '@vueuse/core'

watchOnce(source, () => {
  // 仅触发一次
  console.log('源发生变化!')
})

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>,
): 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

Contributors

jorshen

Changelog

No recent changes

Released under the MIT License.