提交 f614cc52 编写于 作者: D DCloud_LXH

fix(h5): rich-text add scopeId attribute

上级 774979e5
import { onMounted, ref, watch } from 'vue'
import { onMounted, ref, watch, getCurrentInstance } from 'vue'
import { defineBuiltInComponent } from '@dcloudio/uni-components'
import parseHtml from './html-parser'
import parseNodes from './nodes-parser'
......@@ -18,14 +18,19 @@ export default /*#__PURE__*/ defineBuiltInComponent({
MODE: 3,
},
props,
setup(props) {
setup(props, ...args) {
const vm = getCurrentInstance()
const rootRef = ref<HTMLElement | null>(null)
function _renderNodes(nodes: string | unknown[]) {
if (typeof nodes === 'string') {
nodes = parseHtml(nodes)
}
const nodeList = parseNodes(nodes, document.createDocumentFragment())
const nodeList = parseNodes(
nodes,
document.createDocumentFragment(),
(vm?.root.type as any).__scopeId || ''
)
rootRef.value!.firstElementChild!.innerHTML = ''
rootRef.value!.firstElementChild!.appendChild(nodeList)
}
......
......@@ -96,7 +96,7 @@ function decodeEntities(htmlString) {
)
}
export default function parseNodes(nodes, parentNode) {
export default function parseNodes(nodes, parentNode, scopeId) {
nodes.forEach(function (node) {
if (!isPlainObject(node)) {
return
......@@ -124,6 +124,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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册