Skip to content

watchOnce

类别
导出体积
123 B
上次更改
1 hour 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">,
):
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

源码

源码文档

贡献者

一纸忘忧

更新日志

没有最近的更新日志