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