From 4f87f081d06a7cefece1dae4701e1d0c1bcf9a7c Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Fri, 8 Oct 2021 16:52:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(h5):=20rich-text=20=E5=9C=A8=20h5=20?= =?UTF-8?q?=E7=AB=AF=20nodes=20=E5=B1=9E=E6=80=A7=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20class=20=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/components/rich-text/index.vue | 2 +- src/core/view/components/rich-text/nodes-parser.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/view/components/rich-text/index.vue b/src/core/view/components/rich-text/index.vue index cb6d6da1f..cada87602 100644 --- a/src/core/view/components/rich-text/index.vue +++ b/src/core/view/components/rich-text/index.vue @@ -38,7 +38,7 @@ export default { if (typeof nodes === 'string') { nodes = parseHtml(nodes) } - const nodeList = parseNodes(nodes, document.createDocumentFragment()) + const nodeList = parseNodes(nodes, document.createDocumentFragment(), this) nodeList.appendChild(this.$refs.sensor.$el) const content = this.$refs.content content.innerHTML = '' diff --git a/src/core/view/components/rich-text/nodes-parser.js b/src/core/view/components/rich-text/nodes-parser.js index 684444ff4..d94b65012 100644 --- a/src/core/view/components/rich-text/nodes-parser.js +++ b/src/core/view/components/rich-text/nodes-parser.js @@ -96,7 +96,13 @@ function decodeEntities (htmlString) { }) } -export default function parseNodes (nodes, parentNode) { +export default function parseNodes (nodes, parentNode, $vm) { + let scopeId = '' + while ($vm) { + !scopeId && (scopeId = $vm.$options._scopeId) + $vm = $vm.$parent + } + nodes.forEach(function (node) { if (!isPlainObject(node)) { return @@ -124,6 +130,7 @@ export default function parseNodes (nodes, parentNode) { Array.isArray(value) && (value = value.join(' ')) case 'style': elem.setAttribute(name, value) + scopeId && elem.setAttribute(scopeId, '') break default: if (tagAttrs.indexOf(name) !== -1) { @@ -146,4 +153,4 @@ export default function parseNodes (nodes, parentNode) { } }) return parentNode -} +} -- GitLab