需要引入html-view文件
1/js 代碼
const HtmlParser=require('../../utils/html-view/index') data: { coupon_text:"", } let mobiledesc='<div><img src="../../1.png"></div>' if(mobiledesc){ let coupon_text=new HtmlParser(mobiledesc).nodes; this.setData({ coupon_text }) }else{ this.setData({ coupon_text:'' }) }
2/ wxml代碼
<view wx:if="{{coupon_text}}" class="{{iPhoneXStyle?'wap-chooseticket-footer-diff-iponex':'wap-chooseticket-footer-diff'}}"> <import src="../../utils/html-view/index.wxml" /> <template is="html-view" data="{{data: coupon_text}}" /> </view>
3/最后一步,需要在項目中放入html-view整個文件夾,文件夾的可以在github上面下載