From 9641f5b82ac2b63e53d44e1e3c009150b1032bca Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 23 Mar 2023 11:50:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dref=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=BC=BA=E5=A4=B1=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/html.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index e1740f5..3311b0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bd/core", - "version": "1.5.12", + "version": "1.5.13", "type": "module", "description": "百搭UI组件库的核心", "main": "dist/index.js", diff --git a/src/html.js b/src/html.js index cba94db..ce68b92 100644 --- a/src/html.js +++ b/src/html.js @@ -289,7 +289,7 @@ class TemplateInstance { #checkRef(node, walker, options) { do { - if (node?.nodeType === 1 && node?.getAttribute('ref')) { + if (node && node.nodeType === 1 && node.getAttribute('ref')) { options.host.$refs[node.getAttribute('ref')] = node node.removeAttribute('ref') } @@ -316,6 +316,12 @@ class TemplateInstance { this.#checkRef(node, walker, options) } else { while (templatePart !== void 0) { + if (node.nodeType === 1 && node.getAttribute('ref')) { + if (options.host.$refs) { + options.host.$refs[node.getAttribute('ref')] = node + node.removeAttribute('ref') + } + } if (nodeIndex === templatePart.index) { let part if (templatePart.type === CHILD_PART) { @@ -331,12 +337,6 @@ class TemplateInstance { } else if (templatePart.type === ELEMENT_PART) { part = new ElementPart(node, this, options) } - if (node.nodeType === 1 && node.getAttribute('ref')) { - if (options.host.$refs) { - options.host.$refs[node.getAttribute('ref')] = node - node.removeAttribute('ref') - } - } this._parts.push(part) templatePart = parts[++partIndex] }