deepFor(nodes) {
nodes.forEach(item => {
if (item.name == 'img') {
if (!item.attrs) {
item.attrs = {}
}
item.attrs.style = 'width:100%'
}
if (item.children && item.children.length > 0) {
this.deepFor(item.children)
}
})
return nodes
},
循环nodes 数组 给img标签加上宽度100%的属性
HTMLParser链接https://uniapp.dcloud.io/component/rich-text
因section不被uniapp rich-text支持 所以需转成div(微信小程序似乎没毛病 支付宝小程序会出现该问题)
showPage = showPage.replace(/<section/g, '<div').replace(/\/section>/g, '/div>');
nodes = HTMLParser(showPage)
nodes = deepFor(nodes)
循环出来的nodes 可以赋给rich-text了