1. rich-text
注意使用这个标签需要绑定写法,最好不要用字符串的格式,因为会降低性能,下面是官网解释
nodes 值为 HTML String 时,在组件内部将自动解析为节点列表,推荐直接使用 Array 类型避免内部转换导致的性能下降。App-nvue 和支付宝小程序不支持 HTML String 方式,仅支持直接使用节点列表即 Array 类型,如要使用 HTML String,则需自己将 HTML String 转化为 nodes 数组,可使用 html-parser 转换。
节点列表内的节点现支持两种类型,通过 type 来区分,分别是元素节点和文本节点,默认是元素节点,在富文本区域里显示的 HTML 节点。
2.具体实现
<view v-if="item.extPropsDesc">
<rich-text :nodes="nodes(item.extPropsDesc)"></rich-text>
</view>
<script>
data() {
return {
nodes(data) {
return [{
children: [{
type: 'text',
attrs: {
class: 'msg-name',
style: 'color:#888'
},
text: '扩展属性: '
}, {
type: 'text',
attrs: {
class: 'msg-name'
},
text: data
}]
}]
},
};
},
</script>
<style scoped>
.msg-name {
line-height: 50upx;
font-size: 16px;
color: #000;
line-height: 35rpx;
}
</style>
最好是把当前行从左到右全部需要显示的文字都放在这个nodes里面,单独在 rich-text 外面写其他的html结构,不好控制样式,原因很简单,( nvue:恶 心 ),不过多解释