1. 效果图
2. wxml代码
<!-- rich-text富文本,可渲染html -->
<view class="page-body">
<view class="page-section">
<view class="page-section-title">传入html字符串</view>
<view class="rich-text-wrp">
<rich-text nodes="{{html}}" bindtap="tap"></rich-text>
</view>
</view>
<view class="page-section">
<view class="page-section-title">传入节点列表</view>
<view class="rich-text-wrp">
<rich-text nodes="{{nodes}}" bindtap="tap"></rich-text>
</view>
</view>
</view>
3. js代码
Page({
data: {
html: '<div class="div_class" style="line-height: 60px; color: red;">Hello World!</div>',
nodes: [{
name: 'div',
attrs: {
class: 'div_class',
style: 'line-height: 60px; color: red;'
},
children: [{
type: 'text',
text: 'Hello World!'
}]
}]
},
tap() {
console.log('tap')
}
})