微信小程序 —— 微信小程序解析html格式的内容
- 下载并把wxParse放到小程序的目录中
- github下载地址:https://github.com/icindy/wxParse
- 页面引入
- 在app.wxss中引入
@import "/wxParse/wxParse.wxss";
- 在使用的文件中引入WxParse模块使用
// wxml文件
// 引入模板
<import src="../../wxParse/wxParse.wxml" />
<view class="wxParse">
// article为绑定的名字
<template is="wxParse" data="{{wxParseData:article.nodes}}" />
</view>
// js文件
var WxParse = require('../../wxParse/wxParse.js');
// html数据
getData() {
let that = this
wx.request({
url: 'xxx',
method: 'GET',
header: {
'content-type': 'application/json; charset=utf-8;'
},
success: (res) => {
var article = `${res.data}`
WxParse.wxParse('article', 'html', article, that, 5);
},
fail() {
console.log('接口有误,请检查')
},
complete(res){
}
});
},
- WxParse
WxParse.wxParse(bindName , type, data, target,imagePadding)
- 1.bindName绑定的数据名(必填)
- 2.type可以为html或者md(必填)
- 3.data为传入的具体数据(必填)
- 4.target为Page对象,一般为this(必填)
- 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)