跳到主要内容

watchImmediate

分类
导出大小
117 B
上次更改
上个月

用于观察值并设置 {immediate: true} 的简写

用法

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

ts
import { 
watchImmediate
} from '@vueuse/core'
const
obj
=
ref
('vue-use')
// changing the value from some external store/composables
obj
.
value
= 'VueUse'
watchImmediate
(
obj
, (
updated
) => {
console
.
log
(
updated
) // Console.log will be logged twice
})

类型声明

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

来源

源码文档

贡献者

Anthony Fu
Arthur Darkstone
Anthony Fu
Nate Oliver
山吹色御守
jp-liu
Andrew Ferreira
Kyrie890514
Alex Liu
丶远方
Magomed Chemurziev
Hammad Asif

更新日志

b8102 - feat(watch): 更新 watchExtractedObservable, watchDebounced, watchDeep, watchImmediate, watchOnce, watchThrottled 和 watchWithFilter 中 watch 返回值的类型错误 (#4896)
00a72 - fix(types): 更新 watch 函数的类型转换以使用 WatchSource (#4966)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
0716d - fix(watchDeep): 统一 watch 函数的重载声明 (#4043)
v10.2.0
4b4e6 - fix: 修复重载签名 (#3114)
v10.1.0
8f6a0 - feat(watch): watchImmediatewatchDeep 支持重载 (#2998)

根据 MIT 许可证发布。