diff --git a/package.json b/package.json index 93df4ac..16d44ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bd/core", - "version": "1.5.9", + "version": "1.5.10", "type": "module", "description": "百搭UI组件库的核心", "main": "dist/index.js", diff --git a/src/html.js b/src/html.js index 986a15b..e8e0a6f 100644 --- a/src/html.js +++ b/src/html.js @@ -286,6 +286,16 @@ class TemplateInstance { get _$isConnected() { return this._$parent._$isConnected } + + #checkRef(node, walker, options) { + do { + if (node.nodeType === 1 && node.getAttribute('ref')) { + options.host.$refs[node.getAttribute('ref')] = node + node.removeAttribute('ref') + } + } while ((node = walker.nextNode()) !== null) + } + _clone(options) { let { el: { content }, @@ -303,12 +313,7 @@ class TemplateInstance { let templatePart = parts[0] // 没有动态绑定时, 查一遍是否有ref属性 if (templatePart === void 0) { - do { - if (node.nodeType === 1 && node.getAttribute('ref')) { - options.host.$refs[node.getAttribute('ref')] = node - node.removeAttribute('ref') - } - } while ((node = walker.nextNode()) !== null) + this.#checkRef(node, walker, options) } else { while (templatePart !== void 0) { if (nodeIndex === templatePart.index) { @@ -329,6 +334,7 @@ class TemplateInstance { 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) @@ -344,6 +350,8 @@ class TemplateInstance { nodeIndex++ } } + // 再检查剩下没有动态绑定的节点 + this.#checkRef(node, walker, options) } return fragment