在小程序开发中遇到了小程序不支持html标签,这在获取后端提供的”商品详情页面“产生了很大难题,在网上找到了wxParse富文本插件,官方地址:wxParse
详细教程:
1、打开网站,将wxParse文件夹复制到项目中
2、在使用的页面导入文件
首先在xx.js导入文件,在文件头写上:
var WxParse =
require(
'../wxParse/wxParse.js')
如图:
其次在xx.wxml导入文件,在文件头写上:
<
import
src=
"../wxParse/wxParse.wxml"
/
>
如图:
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);
4、在wxml中引入模板
//这里data中article为bindName
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>
感谢wxParse作者写出这么好的插件