From 3bc02e2e13f3041eb1d00fa832e622ca6060d284 Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 16 Mar 2023 14:32:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=84=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index 03908c0..a4c4123 100644 --- a/src/index.js +++ b/src/index.js @@ -63,7 +63,7 @@ export class Component extends HTMLElement { }, enumerable: false } - + this.prototype[key] = options.default this[__props__].set(name, options) Object.defineProperty(this.prototype, name, descriptor) } @@ -102,11 +102,7 @@ export class Component extends HTMLElement { this.root = this.shadowRoot || this.attachShadow({ mode: 'open' }) this[__changed_props__] = new Map() // 记录本次变化的属性 - // 初始化 props - this.constructor[__props__].forEach((options, prop) => { - this[prop] = options.default - }) - // 若无定义props时, 手动执行一次渲染 + // 手动执行一次渲染 if (this[__pending__] === false) { this[__pending__] = true nextTick(_ => this[__updated__]()) @@ -132,7 +128,7 @@ export class Component extends HTMLElement { if (old === val) { return } - this[__attr2prop__](name, val) + this[__attr2prop__](name, val, old) } /** @@ -173,9 +169,8 @@ export class Component extends HTMLElement { * @param name * @param value */ - [__attr2prop__](name, value) { + [__attr2prop__](name, value, old) { let options = this.#getPropOptions(name) - this[name] = fixedValue(value, options) }