关于微信小程序的富文本标签的开发环境使用

1,464 阅读1分钟

wxml下添加标签

<rich-text nodes="{{msg}}"></rich-text> 

js下加工数据

  data: {
    msg:''
  },
   onLoad: function (options) {
    var that= this
        wx.request({
          url: '', //仅为示例,并非真实的接口地址
          method:'post',
          header: {
            'content-type': 'application/json' // 默认值
          },
          success(res) {
            console.log(res.data)
            that.setData({
              msg: res.data.ymxq.replace(/\<p>/g, "<p style='line-height: 24px; font-size:15px;text-align: justify;margin:10px 0;'>")
            })
          }
        })
  },

注意这里是p标签所以替换样式这样写。