主题
watchDeep
{deep: true}
监视值的简写
¥Shorthand for watching value with {deep: true}
用法
¥Usage
与 watch
类似,但与 { deep: true }
相同
¥Similar to watch
, but with { 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
})
类型声明
typescript
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">,
): WatchStopHandle
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">,
): WatchStopHandle
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">,
): WatchStopHandle