修复没有动态绑定时, ref不生效的bug

pull/1/head 1.5.4
yutent 2023-03-20 11:29:19 +08:00
parent 58d4277964
commit 0eecaa22dc
2 changed files with 42 additions and 36 deletions

View File

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

View File

@ -301,7 +301,15 @@ class TemplateInstance {
let nodeIndex = 0 let nodeIndex = 0
let partIndex = 0 let partIndex = 0
let templatePart = parts[0] 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)
} else {
while (templatePart !== void 0) { while (templatePart !== void 0) {
if (nodeIndex === templatePart.index) { if (nodeIndex === templatePart.index) {
let part let part
@ -318,7 +326,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)
} }
// console.log(node)
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
@ -337,6 +344,8 @@ class TemplateInstance {
nodeIndex++ nodeIndex++
} }
} }
}
return fragment return fragment
} }
_update(values) { _update(values) {
@ -410,7 +419,6 @@ class ChildPart {
_commitNode(value) { _commitNode(value) {
if (this._$committedValue !== value) { if (this._$committedValue !== value) {
this.#clear() this.#clear()
this._$committedValue = this._insert(value) this._$committedValue = this._insert(value)
} }
} }
@ -669,8 +677,6 @@ export function render(value, container, options = {}) {
} }
part._$setValue(value) part._$setValue(value)
// console.log(container, options.host, options.host.$refs)
return part return part
} }