wxParse-微信小程序HTML標籤解析插件的使用
背景說明
小程序默認是不支持html標籤的渲染,在遇到html內容的時候,需要做一個html到wxml的轉換;
組件說明
-
組件支持HTML及markdown解析;
基本使用方法
- Copy文件夾
wxParse
- wxParse/
- 引入必要文件
// 在使用的View中引入WxParse模塊
var WxParse = require('../../wxParse/wxParse.js');
//在使用的Wxss中引入WxParse.css,可以在app.wxss
@import "/wxParse/wxParse.wxss";
- 數據綁定
var article = '<div>我是HTML代碼</div>';
/**
* WxParse.wxParse(bindName , type, data, target,imagePadding)
* 1.bindName綁定的數據名(必填)
* 2.type可以爲html或者md(必填)
* 3.data爲傳入的具體數據(必填)
* 4.target爲Page對象,一般爲this(必填)
* 5.imagePadding爲當圖片自適應是左右的單一padding(默認爲0,可選)
*/
var that = this;
WxParse.wxParse('article', 'html', article, that, 5);
- 模版引用
// 引入模板
<import src="你的路徑/wxParse/wxParse.wxml"/>
//這裏data中article爲bindName
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>
wepy 使用
‘…/…/libs’ 爲wxParse在項目中的存放路徑,可自行修改
-
Copy文件夾
wxParse
-
引入必要文件
//在使用的wpy中引入WxParse模塊
import WxParse from '../../libs/wxParse/wxParse.js'
//在使用的wpy style 中引入WxParse.css,可以在app.wxss
@import "../../libs/wxParse/wxParse.wxss";
- 數據綁定
var article = '<div>我是HTML代碼</div>';
var that = this;
WxParse.wxParse('article', 'html', article, that, 5);
- 模版引用
// 引入模板
<import src="../../libs/wxParse/wxParse.wxml"/>
//這裏data中article爲bindName
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>