github下载地址:
https://github.com/icindy/wxParse
。
- 下载完成后,复制 wxParse 文件夹到项目目录中(例如: utils 目录下)。
- 在需要使用的 JS 文件中引入 wxParse.js 文件。
var WxParse = require('../../utils/wxParse/wxParse.js');
- 在 CSS 文件中引入样式文件。
@import "./utils/wxParse/wxParse.wxss";
- 在 HTML 中引入对应的模板文件。
<import src="../../utils//wxParse/wxParse.wxml"/> // data 中 article 为 bindName <template is="wxParse" data="{{wxParseData:article.nodes}}"/>
- 数据绑定.
WxParse.wxParse(bindName , type, data, target, imagePadding)
- bindName:绑定的数据名(必填)。
- type:可以为 html 或者 md (必填)。
- data:为传入的具体数据(必填)。
- target:为Page对象,一般为this(必填)。
- imagePadding:为当图片自适应是左右的单一 padding (默认为0,可选).
var article = '<div>我是HTML代码</div>'; var that = this; WxParse.wxParse('article', 'html', article, that, 5);