微信小程序插件wxParse的使用
生活随笔
收集整理的這篇文章主要介紹了
微信小程序插件wxParse的使用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
由于微信小程序不支持后臺(tái)富文本編輯器編輯的html,需要使用wxParse 這個(gè)插件來(lái)解析,下面介紹一下這個(gè)插件的使用方法。
1. 下載插件
在GigHub上面找到插件Demo,地址為?https://github.com/icindy/wxParse,把Demo里面的wxParse目錄拷貝到項(xiàng)目里面.
2. 在當(dāng)前頁(yè)面的JS里引入wxParse.js
var WxParse = require('../../wxParse/wxParse.js'); Page({data: {},onLoad: function() {var that = this;// 映射表情包WxParse.emojisInit('[]', "/wxParse/emojis/", {"00": "00.gif","01": "01.gif","02": "02.gif","03": "03.gif","04": "04.gif","05": "05.gif","06": "06.gif","07": "07.gif","08": "08.gif","09": "09.gif","09": "09.gif","10": "10.gif","11": "11.gif","12": "12.gif","13": "13.gif","14": "14.gif","15": "15.gif","16": "16.gif","17": "17.gif","18": "18.gif","19": "19.gif",});var article = `<div>從后端獲取的HTML格式文件</div>`;WxParse.wxParse('article', 'html', article, that, 5);// WxParse.wxParse(bindName, type, data, target, imagePadding);// bindName綁定的數(shù)據(jù)名(必填)// type可以為html或者md(必填)// data為傳入的具體數(shù)據(jù)(必填)// target為Page對(duì)象, 一般為this(必填)// imagePadding為當(dāng)圖片自適應(yīng)是左右的單一padding(默認(rèn)為0, 可選)}})3. 在全局app.wxss引入wxParse.wxss
@import "wxParse/wxParse.wxss";4. 在當(dāng)前頁(yè)面wxml中引入wxParse.wxml
<import src="../../wxParse/wxParse.wxml"/> <view class="wxParse"><!-- 這里data中article為bindName --><template is="wxParse" data="{{wxParseData:article.nodes}}"/> </view>總結(jié)
以上是生活随笔為你收集整理的微信小程序插件wxParse的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Zookeeper原理和实战开发经典视频
- 下一篇: [BZOJ1669][Usaco2006