From 0483d6efc37517825ce0d15f22e4193514fb8e92 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 4 Sep 2023 14:10:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B1=9E=E6=80=A7=E5=AE=9A?= =?UTF-8?q?=E4=B9=89,=20=E6=94=AF=E6=8C=81=E6=B7=B1=E5=B1=82=E4=BB=A3?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2a0a265..efc6e74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wkit", - "version": "1.10.5", + "version": "1.10.6", "type": "module", "description": "A library for building fast, lightweight web components.", "main": "dist/index.js", diff --git a/src/index.js b/src/index.js index 685417b..fda8e55 100644 --- a/src/index.js +++ b/src/index.js @@ -201,12 +201,20 @@ export class Component extends HTMLElement { #createProxy(name, options, newValue) { return new Proxy(newValue || options.default, { - set: (target, prop, value) => { + get: (target, prop, receiver) => { + let value = Reflect.get(target, prop, receiver) + // 当访问的值是对象时,需要对这个对象也进行代理 + if (typeof value === 'object') { + return this.#createProxy(value) + } + return value + }, + set: (target, prop, value, receiver) => { if (prop === 'length' && options.type === Array) { return true } let oldValue = target[prop] - target[prop] = value + Reflect.set(target, key, value, receiver) this.$requestUpdate(name) if (options.observer) {