在微信小程序中识别html标签的方法(wxParse)

来源:互联网 发布:mac宽带连接说鉴定失败 编辑:程序博客网 时间:2024/06/06 00:38

在小程序开发中遇到了小程序不支持html标签,这在获取后端提供的”商品详情页面“产生了很大难题,在网上找到了wxParse富文本插件,官方地址:wxParse


详细教程:

1、打开网站,将wxParse文件夹复制到项目中


2、在使用的页面导入文件

首先在xx.js导入文件,在文件头写上:

var WxParse = require('../wxParse/wxParse.js')

如图:


其次在xx.wxml导入文件,在文件头写上:

<import src="../wxParse/wxParse.wxml"/>

如图:


3、获取到数据以后


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作者写出这么好的插件

原创粉丝点击