diff --git a/package.json b/package.json index 8ba5344..6df16cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bd/core", - "version": "1.5.0", + "version": "1.5.1", "type": "module", "description": "百搭UI组件库的核心", "main": "dist/index.js", diff --git a/src/html.js b/src/html.js index dece7ce..d852695 100644 --- a/src/html.js +++ b/src/html.js @@ -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 } diff --git a/src/index.js b/src/index.js index 5fcd408..9377616 100644 --- a/src/index.js +++ b/src/index.js @@ -99,6 +99,7 @@ export class Component extends HTMLElement { value: Object.create(null), enumerable: false }) + this.created() }