微信小程序rich-text组件显示富文本且不支持a标签的herf属性

微信小程序rich-text组件用于显示富文本,支持部分html节点及属性,全局支持class和style属性,不支持id属性。

使用格式

<rich-text nodes="{{nodes}}" bindtap="tap"></rich-text>

示例代码

在开发者工具中预览效果

Page({
  data: {
    nodes: [{
      name: 'div',
      attrs: {
        class: 'div_class',
        style: 'line-height: 60px; color: red;'
      },
      children: [{
        type: 'text',
        text: 'Hello World!'
      }]
    }]
  },
  tap() {
    console.log('tap')
  }
})

题外话:rich-text是支持a节点的,但是实际上 herf 是无效的,貌似只能当作一个节点使用而已。

但是可以通过 bindtap 来实现跳转

参考微信官方文档:rich-text组件