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) }