微信小程序 解析html格式內容


需要引入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上面下載


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM