rich-text 富文本组件自定义的nodes如何修改?
自定义nodes模块
const imgGrid = function () {
const obj = {
name: 'p',
attrs: {
class: 'rich-grid-2'
},
children: [
{
name: 'div',
attrs: {
class: 'img-grid'
},
children: [
{
name: 'img',
attrs: {
class: 'img-case',
src: ''
}
}
]
}, {
name: 'div',
attrs: {
class: 'img-grid'
},
children: [
{
name: 'img',
attrs: {
class: 'img-case',
src: ''
}
}
]
}, {
name: 'div',
attrs: {
class: 'grid-icon'
},
children: [
{
type: 'text',
text: 'Vs'
}
]
}
]
};
return obj
};
export { imgGrid }
js
onLoad: function (options) { let imgGrid2 = imgGrid(); imgGrid2.children[0].children[0].attrs.src = ''; imgGrid2.children[1].children[0].attrs.src = ''; const h2 = header_h2(); const text = content(); h2.children[0].text = '智商税征收机'; text.children[0].text = '智商税征收机'; const text2 = text; const h3 = h2 this.setData({ nodes: [...this.data.nodes, h2, imgGrid2, text, h3, text2] }); console.log("nodes => ", this.data.nodes); },
wxml
<rich-text nodes="{{nodes}}"></rich-text>