From b5a9ef0695fe5cf81f77d9d26d70345270897e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Tue, 23 Oct 2018 11:45:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83=E7=BB=84=E4=BB=B6slot?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/00-generate.js | 2 +- src/15-component.js | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b4f05c1..6f819ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anot", - "version": "1.0.4", + "version": "1.0.5", "description": "Anot - 迷你mvvm框架", "main": "dist/anot.js", "files": [ diff --git a/src/00-generate.js b/src/00-generate.js index cedf88e..f9e3f3b 100644 --- a/src/00-generate.js +++ b/src/00-generate.js @@ -12,7 +12,7 @@ var DOC = window.document var head = DOC.head //HEAD元素 head.insertAdjacentHTML( 'afterBegin', - '' + '' ) var ifGroup = head.firstChild diff --git a/src/15-component.js b/src/15-component.js index 7987f8e..44e678f 100644 --- a/src/15-component.js +++ b/src/15-component.js @@ -17,12 +17,24 @@ function parseSlot(collections, vms) { arr.forEach(function(elem) { switch (elem.nodeType) { case 1: - var slot = elem.getAttribute('slot') + var isSlotTag = elem.tagName === 'SLOT' + var slotKey = null + var isSlotAttr = elem.getAttribute('slot') - if (slot) { - obj[slot] = obj[slot] || [] + if (isSlotTag) { + slotKey = elem.name || elem.getAttribute('name') + } else if (isSlotAttr) { + slotKey = isSlotAttr + } + + if (slotKey) { + obj[slotKey] = obj[slotKey] || [] elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) + if (isSlotTag) { + obj[slotKey].push(elem.innerHTML) + } else { + obj[slotKey].push(elem.outerHTML) + } } else { var txt = elem.outerHTML if (isWidget(elem) || /:[\w-]*=".*"/.test(txt)) {