微信小程序rich-text解析後端html標籤

直接上代碼

小程序頁面

<rich-text type="text" nodes={{content}}></rich-text>

數據層

data(){
    return {content:""},
},
methods:{
   getHtml(){
      wx.request({	
          url:api+"api/mobile/homepage.php?choice=2&id=2",
	  method:"get",
	  dataType:'json',
	  success: (res) => {
	  // 返回的json數據
 		console.log(res.data.content);
                this.content=this.escape2Html
                (res.data.content)
          },
      });
   },
    //解析html
     escape2Html: function (str) {
      var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
      return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; });
     },

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章