小程序view标签转div标签

var temp = WxParse.wxParse('article', 'html', that.data.content.content, that, 5);
that.setData({
article: temp,

})



微信小程序使用富文本插件wxPars兼容html标签(div,p,li,span,img)
日期:2017-12-29 20:02 浏览量: 169
首先去  https://github.com/icindy/wxParse  下载wxParse,只拷贝wxParse文件夹即可。

基本使用方法
Copy文件夹wxParse 



- wxParse/
  -wxParse.js(必须存在)
  -html2json.js(必须存在)
  -htmlparser.js(必须存在)
  -showdown.js(必须存在)
  -wxDiscode.js(必须存在)
  -wxParse.wxml(必须存在)
  -wxParse.wxss(必须存在)
  -emojis(可选)

引入必要文件
 
//在使用的Wxss中引入WxParse.css,可以在app.wxss
@import "/wxParse/wxParse.wxss";

// 在.js中引入赋值定义
var WxParse = require('../../wxParse/wxParse.js');

 that.setData({
            article_content:WxParse.wxParse('infobody', 'html', res.data.infobody, that, 5)
                     })  

下面我们来简单的说一下wxParse参数说明

* WxParse.wxParse(bindName , type, data, target,imagePadding)
* 1.bindName绑定的数据名(必填)
* 2.type可以为html或者md(必填)
* 3.data为传入的具体数据(必填)
* 4.target为Page对象,一般为this(必填)
* 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
 
//在wxml中引入模板
<view class="wxParse">
<template is="wxParse" data="{{wxParseData:infobody.nodes}}"/>
</view>


猜你喜欢

转载自blog.csdn.net/weixin_41871290/article/details/80312372