修复ref标识的解析

pull/1/head 1.5.1
yutent 2023-03-17 10:59:48 +08:00
parent 8cebdd1994
commit d0af1270dc
3 changed files with 10 additions and 8 deletions

View File

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

View File

@ -134,7 +134,7 @@ function getTemplateHtml(strings, type) {
return [htmlResult, attrNames]
}
class Template {
constructor({ strings, values, ['__dom_type__']: type }, options) {
constructor({ strings, ['__dom_type__']: type }, options) {
this.parts = []
let node
let nodeIndex = 0
@ -157,12 +157,6 @@ class Template {
let attrsToRemove = []
for (let name of node.getAttributeNames()) {
if (name === 'ref') {
options.host.$refs[node.getAttribute('ref')] = node
node.removeAttribute('ref')
continue
}
if (
name.endsWith(boundAttributeSuffix) ||
name.startsWith(marker)
@ -324,6 +318,11 @@ 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
}
}
this._parts.push(part)
templatePart = parts[++partIndex]
}
@ -669,6 +668,8 @@ export function render(value, container, options = {}) {
}
part._$setValue(value)
// console.log(container, options.host, options.host.$refs)
return part
}

View File

@ -99,6 +99,7 @@ export class Component extends HTMLElement {
value: Object.create(null),
enumerable: false
})
this.created()
}