Small program rich text WxParse plugin

Reference https://blog.csdn.net/loveyoulouyou/article/details/83413628

Download WxParse plug-in, plug-in address https://github.com/icindy/wxParse

css part:

@import "../../utils/wxParse/wxParse.wxss";

html part:

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

<block wx:for='{ {richText}}' wx:for-index='itemIndex' wx:for-item='item' wx:key=''>

<view class="listItem">

<image src="{ {item.img}}"></image>

<view>{ {item.title}}</view>

<view>

<template is="wxParse" data="{ {wxParseData:artileList[itemIndex]}}"/>

</view>

</view>

</block>

js part:

var WxParse = require("../../utils/wxParse/wxParse.js");

Page({

/**

* Initial data of the page

*/

data: {

richText:[

{

'img': 'https://csdnimg.cn/cdn/content-toolbar/csdn-xie.png',

'title':'First title',

'des':'<p>The first description <span>hahahahahasado or</span></p>'

},

{

'img': 'https://csdnimg.cn/public/common/toolbar/images/message-icon.png',

'title':'Second title',

'des':'<p>The second description <span>hahahahahasado or</span></p>'

},

{

'img': 'https://csdnimg.cn/public/common/toolbar/images/vipimg.png',

'title':'The third title',

'des':'<p>The third description <span>hahahahahasado or</span></p>'

},

]

},

/**

* Life cycle function-monitor page display

*/

onShow: function () {

var that = this;

var richText = that.data.richText;

for (var i = 0; i < richText.length; i++) {

WxParse.wxParse('content' + i, 'html', richText[i]['des'], that);

if (i === richText.length - 1) {

WxParse.wxParseTemArray("artileList", 'content', richText.length, that)

}

}

},

 

Guess you like

Origin blog.csdn.net/u012011360/article/details/100664402