修复ref解析丢失的bug

pull/1/head 1.5.10
yutent 2023-03-22 18:49:46 +08:00
parent 7669b3b713
commit c416622f72
2 changed files with 15 additions and 7 deletions

View File

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

View File

@ -286,6 +286,16 @@ class TemplateInstance {
get _$isConnected() { get _$isConnected() {
return this._$parent._$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) { _clone(options) {
let { let {
el: { content }, el: { content },
@ -303,12 +313,7 @@ class TemplateInstance {
let templatePart = parts[0] let templatePart = parts[0]
// 没有动态绑定时, 查一遍是否有ref属性 // 没有动态绑定时, 查一遍是否有ref属性
if (templatePart === void 0) { if (templatePart === void 0) {
do { this.#checkRef(node, walker, options)
if (node.nodeType === 1 && node.getAttribute('ref')) {
options.host.$refs[node.getAttribute('ref')] = node
node.removeAttribute('ref')
}
} while ((node = walker.nextNode()) !== null)
} else { } else {
while (templatePart !== void 0) { while (templatePart !== void 0) {
if (nodeIndex === templatePart.index) { if (nodeIndex === templatePart.index) {
@ -329,6 +334,7 @@ class TemplateInstance {
if (node.nodeType === 1 && node.getAttribute('ref')) { if (node.nodeType === 1 && node.getAttribute('ref')) {
if (options.host.$refs) { if (options.host.$refs) {
options.host.$refs[node.getAttribute('ref')] = node options.host.$refs[node.getAttribute('ref')] = node
node.removeAttribute('ref')
} }
} }
this._parts.push(part) this._parts.push(part)
@ -344,6 +350,8 @@ class TemplateInstance {
nodeIndex++ nodeIndex++
} }
} }
// 再检查剩下没有动态绑定的节点
this.#checkRef(node, walker, options)
} }
return fragment return fragment