跳到主要内容

watchDeep

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

使用 {deep: true} 监听值的简写。

用法

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

ts
import { 
watchDeep
} from '@vueuse/core'
const
nestedObject
=
ref
({
foo
: {
bar
: {
deep
: 5 } } })
watchDeep
(
nestedObject
, (
updated
) => {
console
.
log
(
updated
)
})
onMounted
(() => {
nestedObject
.
value
.
foo
.
bar
.
deep
= 10
})

类型声明

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

来源

源代码文档

贡献者

Anthony Fu
Arthur Darkstone
Anthony Fu
山吹色御守
jp-liu
Kyrie890514
Alex Liu
丶远方
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: 统一 watch 函数的重载声明 (#4043)
v10.1.0
8f6a0 - feat(watch): watchImmediatewatchDeep 支持重载 (#2998)

根据 MIT 许可证发布。