From d0af1270dcb25707747225860e1783222986686e Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 17 Mar 2023 10:59:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dref=E6=A0=87=E8=AF=86?= =?UTF-8?q?=E7=9A=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/html.js | 15 ++++++++------- src/index.js | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) 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() }