首先到https://github.com/icindy/wxParse下载wxParse包,下载后是一个小程序demo可以直接放入小程序开发工具中进行测 试以及查看。之后在自己项目中进行部署,只需要拷贝wxParse文件夹即可
1、引入wxss
@import "../wxParse/wxParse.wxss";
2、引入wxml
<import src="../wxParse/wxParse.wxml"/>
<view class="wxParse">
<template is="wxParse" data="{{wxParseData:article_content.nodes}}"/>
</view>
3、引入js并加载数据
var app = getApp();
var WxParse = require('../wxParse/wxParse.js');
Page({
data: {
motto: 'jxcat',
serverUrl: app.globalData.ajaxUrl,
baseUrl: app.globalData.baseUrl,
title: "文章详情",
article_title: "",
article_content: "",
},
onLoad: function (options) {
var that = this
var result
//serverUrl = app.globalData.ajaxUrl
wx.request({
url: app.globalData.ajaxUrl,
data: {
m: 'api',
c: 'article' ,
a: 'info',
aid: options.aid
},
header: {
'content-type': 'application/json'
},
success: function(res) {
that.setData({
article_title:res.data.article_title,
article_content:WxParse.wxParse('article_content', 'html', res.data.article_content, that, 5)
})
}
})
//request
}
})