Skip to content

watchOnce

类别
导出体积
123 B
上次更改
3 weeks ago

用于观看值的缩写形式,带有 { once: true }。回调函数触发一次后,观察者将停止。

有关完整细节,请参见 Vue 的文档

使用方法

类似于 watch,但带有 { once: true }

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

类型声明

ts
export declare function 
watchOnce
<
T
extends
Readonly
<
WatchSource
<unknown>[]>>(
source
: [...
T
],
cb
:
WatchCallback
<
MapSources
<
T
>,
MapOldSources
<
T
, true>>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchStopHandle
export declare function
watchOnce
<
T
>(
source
:
WatchSource
<
T
>,
cb
:
WatchCallback
<
T
,
T
| undefined>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchStopHandle
export declare function
watchOnce
<
T
extends object>(
source
:
T
,
cb
:
WatchCallback
<
T
,
T
| undefined>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchStopHandle

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
Arthur Darkstone
Fernando Fernández
Howard Guo
Valery
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

更新日志

00a72 - fix(types): update type casting for watch functions to use WatchSource (#4966)
08f7d - feat: use vue's native once behaviour (#4750)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
bb0a7 - feat: return function for manual watcher stopping (#3475)