From 9b76cfa14112c2621495d052b5565936a6c449d8 Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 23 Mar 2023 11:17:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BB=84=E4=BB=B6=E5=86=85?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84mounted=E4=B8=8D=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/constants.js | 1 - src/index.js | 22 +++++++--------------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 5fdbe05..e1740f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bd/core", - "version": "1.5.11", + "version": "1.5.12", "type": "module", "description": "百搭UI组件库的核心", "main": "dist/index.js", diff --git a/src/constants.js b/src/constants.js index 754f79d..116ac58 100644 --- a/src/constants.js +++ b/src/constants.js @@ -51,7 +51,6 @@ export const __attr2prop__ = Symbol('attr2prop') export const __clear_update__ = Symbol('clearupdate') export const __children__ = Symbol('children') export const __updated__ = Symbol('updated') -export const __in_tree__ = Symbol('intree') export const RESET_CSS_STYLE = `* {box-sizing: border-box;margin: 0;padding: 0;}::before,::after {box-sizing: border-box;}` diff --git a/src/index.js b/src/index.js index a310c04..efa07b2 100644 --- a/src/index.js +++ b/src/index.js @@ -19,8 +19,7 @@ import { __attr2prop__, __clear_update__, __children__, - __updated__, - __in_tree__ + __updated__ } from './constants.js' import { css, adoptStyles } from './css.js' import { render, html, svg } from './html.js' @@ -103,10 +102,8 @@ export class Component extends HTMLElement { super() this[__pending__] = false this[__mounted__] = false - this[__in_tree__] = false // 这里提前定义一次, 是为了在connectedCallback之前, 就已有赋值时报错的bug this[__changed_props__] = new Map() // 记录一次渲染周期内变化的属性 - // this[__init__]() this.root = this.shadowRoot || this.attachShadow({ mode: 'open' }) Object.defineProperty(this, '$refs', { @@ -228,17 +225,12 @@ export class Component extends HTMLElement { // 更新回调反馈 [__feedback__](props) { - if (this[__in_tree__] === false) { - this[__in_tree__] = document.body.contains(this) - } - if (this[__in_tree__]) { - // 初始化时不触发updated回调 - if (this[__mounted__] === false) { - this[__mounted__] = true - this.mounted() - } else { - this.updated(props) - } + // 初始化时不触发updated回调 + if (this[__mounted__] === false) { + this[__mounted__] = true + this.mounted() + } else { + this.updated(props) } }