<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)

          2018-5-23    seo達人

          如果您想訂閱本博客內容,每天自動發到您的郵箱中, 請點這里

          1.把wxParse文件全部放入項目。

          2.在wxml中import wxParse.wxml,并把template插入到到對應的位置上

          [html] view plain copy
          1. <!--wxml-->  
          2. <import src="../../../wxParse/wxParse.wxml"/>  
          3. <view class="view-title">{{title}}</view>  
          4. <view class="view-time-box">  
          5.   <text class="view-date">{{date}}</text>  
          6.   <text class="view-time">{{time}}</text>  
          7. </view>  
          8. <template is="wxParse" data="{{wxParseData:article.nodes}}"/>  

          3.在wxss中import wxParse.wxss,并設置樣式;比如‘wxParse-image’是富文本圖片轉化成image組件之后的類名,‘wxParse-p’是p標簽轉化成view組件后設置的類名

          [css] view plain copy
          1. <!--wxss-->  
          2. @import "../../../wxParse/wxParse.wxss";  
          3. page{  
          4.   background#fff;  
          5. }  
          6. .view-title{  
          7.   line-height80rpx;  
          8.   font-size48rpx;  
          9.   color:#0C0C0C;  
          10.   overflowhidden;  
          11.   text-overflow: ellipsis;  
          12.   display: -webkit-box;  
          13.   -webkit-line-clamp: 2;  
          14.   -webkit-box-orient: vertical;  
          15.   max-height190rpx;  
          16.   min-height80rpx;  
          17.   width:690rpx;  
          18.   padding:30rpx 30rpx 0;  
          19. }  
          20. .view-time-box{  
          21.   height66rpx;  
          22.   line-height66rpx;  
          23.   font-size30rpx;  
          24.   color:#999999;  
          25.   margin-bottom40rpx;  
          26.   padding:0 30rpx;  
          27. }  
          28. .view-date{  
          29.   margin-right20rpx;  
          30. }  
          31. .wxParse-img{  
          32.   margin-top:20rpx;  
          33.   displayblock;  
          34.   position:relative;  
          35.   top:0;  
          36.   left:50%;  
          37.   transform: translateX(-50%);  
          38. }  
          39. .wxParse-p{  
          40.   text-indent2em;  
          41.   margin-top:20rpx;  
          42.   color:#0C0C0C;  
          43.   line-height:50rpx;  
          44.   font-size:34rpx;  
          45.   padding:0 30rpx 30rpx;  
          46.   text-alignjustify;  
          47. }  

          4.js

          [javascript] view plain copy
          1. var WxParse = require('../../../wxParse/wxParse.js');  
          2. Page({  
          3.   
          4.   /** 
          5.    * 頁面的初始數據 
          6.    */  
          7.   data: {  
          8.     title: '',  
          9.     date: "",  
          10.     time: "",  
          11.     id: ''  
          12.   },  
          13.   
          14.   /** 
          15.    * 生命周期函數--監聽頁面加載 
          16.    */  
          17.   onLoad: function (options) {  
          18.     this.setData({  
          19.       id:options.id  
          20.     })  
          21.   },  
          22.   onShow: function () {  
          23.     wx.showLoading({  
          24.       title: '加載中...',  
          25.     })  
          26.     var that = this;  
          27.   
          28.     // 模擬獲取數據  
          29.     setTimeout(function () {  
          30.       that.setData({  
          31.         title:'僑寶柑普茶新會陳皮僑寶柑',  
          32.         date:"2018-03-01",  
          33.         time:"13:20:53"  
          34.       })  
          35.       var article = `  
          36.         <img src="../../../imgs/index/s.png"></img>  
          37.     <p>微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)</p>  
          38.     <p>微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)</p>  
          39.         <img src="../../../imgs/index/s.png"></img>  
          40.     <p>近兩年,小青柑的火爆有目共睹,嬌小玲瓏的產品形態、便攜式的消費場景、柑與茶結合的時尚方式以及獨特的口感和養生功效,都在順應著目前年輕化、多元化、便攜化的茶葉消費市場需求,讓它成為了一大爆品。</p>  
          41.       `;  
          42.       /** 
          43.       * WxParse.wxParse(bindName , type, data, target,imagePadding) 
          44.       * 1.bindName綁定的數據名(必填) 
          45.       * 2.type可以為html或者md(必填) 
          46.       * 3.data為傳入的具體數據(必填) 
          47.       * 4.target為Page對象,一般為this(必填) 
          48.       * 5.imagePadding為當圖片自適應是左右的單一padding(默認為0,可選) 
          49.       */  
          50.       WxParse.wxParse('article''html', article, that, 20);  
          51.         
          52.       // 更改數據、獲取新數據完成  
          53.       wx.hideLoading();  
          54.     }, 500)  
          55.   }  
          56. })  
          具體的API可以去GitHub上查看:https://github.com/icindy/wxParse








          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務


          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合