From 164bae388f3e66278ef845275e712f16e59739d5 Mon Sep 17 00:00:00 2001 From: dj Date: Thu, 26 Feb 2026 12:00:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=97=AE=E9=A2=98---"?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=BC=8F=E6=95=B0=E6=8D=AE=E7=9A=84=E6=94=B9?= =?UTF-8?q?=E5=8F=98=E5=B9=B6=E4=B8=8D=E4=BC=9A=E5=BC=95=E8=B5=B7watch?= =?UTF-8?q?=E7=9A=84=E8=A7=A6=E5=8F=91"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/runtime-core/src/apiWatch.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 7a5e5c4..23a92b3 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -1,4 +1,4 @@ -import { EMPTY_OBJ, hasChanged } from '@vue/shared' +import { EMPTY_OBJ, hasChanged, isObject } from '@vue/shared' import { isReactive, ReactiveEffect } from '@vue/reactivity' import { queuePreFlushCb } from '@vue/runtime-core' @@ -28,7 +28,8 @@ function doWatch( //todo //浅拷贝的形式--指向同样的内存空间 const baseGetter = getter - getter = () => baseGetter() + //等同于将source的属性传进去了 + getter = () => traverse(baseGetter()) } let oldValue = {} @@ -58,3 +59,17 @@ function doWatch( effect.stop() } } + +/** + * 本质上是拿value, 出发一次getter行为 + * @param value + */ +export function traverse(value: unknown) { + if (!isObject(value)) { + return value + } + for (const key in value as object) { + traverse((value as object)[key]) + } + return value +}