修复ref解析部分缺失的bug

pull/1/head 1.5.13
yutent 2023-03-23 11:50:28 +08:00
parent 9b76cfa141
commit 9641f5b82a
2 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@bd/core", "name": "@bd/core",
"version": "1.5.12", "version": "1.5.13",
"type": "module", "type": "module",
"description": "百搭UI组件库的核心", "description": "百搭UI组件库的核心",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -289,7 +289,7 @@ class TemplateInstance {
#checkRef(node, walker, options) { #checkRef(node, walker, options) {
do { do {
if (node?.nodeType === 1 && node?.getAttribute('ref')) { if (node && node.nodeType === 1 && node.getAttribute('ref')) {
options.host.$refs[node.getAttribute('ref')] = node options.host.$refs[node.getAttribute('ref')] = node
node.removeAttribute('ref') node.removeAttribute('ref')
} }
@ -316,6 +316,12 @@ class TemplateInstance {
this.#checkRef(node, walker, options) this.#checkRef(node, walker, options)
} else { } else {
while (templatePart !== void 0) { 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) { if (nodeIndex === templatePart.index) {
let part let part
if (templatePart.type === CHILD_PART) { if (templatePart.type === CHILD_PART) {
@ -331,12 +337,6 @@ class TemplateInstance {
} else if (templatePart.type === ELEMENT_PART) { } else if (templatePart.type === ELEMENT_PART) {
part = new ElementPart(node, this, options) 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) this._parts.push(part)
templatePart = parts[++partIndex] templatePart = parts[++partIndex]
} }