微信小程序 解析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/wxss

复制代码
 
.wap-chooseticket-footer-diff {
    width: 100%;
    overflow-x: scroll;
  }
  
  .wap-chooseticket-footer-diff-iponex {
    width: 100%;
    overflow-x: scroll;
  }
  
  .wap-chooseticket-footer-diff view {
    width: 100% !important;
  }
  
  .wap-chooseticket-footer-diff-iponex view {
    width: 100% !important;
  }
  
  .wap-chooseticket-footer-diff .html-view image {
    width: 100% !important;
    display: block;
  }
  
  .wap-chooseticket-footer-diff-iponex .html-view image {
    width: 100% !important;
    display: block;
  }
复制代码

 

4/最后一步,需要在项目中放入html-view整个文件夹,文件夹的可以在github上面下载(可以在github自行搜索html-view)

 

posted @   shuihanxiao  阅读(3969)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
历史上的今天:
2018-09-27 获取汉字首字母,拼音,可实现拼音字母搜索----npm js-pinyin
2018-09-27 获取汉字的拼音首字母--pinyin
2018-09-27 css滚动条样式修改
点击右上角即可分享
微信分享提示