接口标识:show
接口url:https://你的网站/api/index.php?action=show[&id=10]
接口参数:

小程序代码
02 |
url: app.globalData.api + "action=show" , |
04 |
typeid: that.data.typeid, |
06 |
relation: 1,//开启调用相关推荐 |
07 |
aid: app.globalData.aid |
11 |
'content-type' : 'application/x-www-form-urlencoded' , |
12 |
'x-appsecret' : app.globalData.appsecret |
14 |
success: function (res) { |
15 |
var content = res.data.data; |
|
说明:
(1)该页面引入了require('../../utils/util.js'),里边封装的有对时间的处理,因为api返回的是时间戳,需要处理
1 |
content.relations[i].pubdate = util.formatTime(content.relations[i].pubdate, 'Y-M-D' ); |
|
(2)由于小程序不支持直接的html标签,所以引入bdparse插件,具体参考demo。
(3)relation默认关闭,需要修改代码来开启,参考demo
(4)字段中如果有数组,需要进行特殊处理,代码实例:
2 |
if (content.pictureurls){ |
3 |
content.pictureurls = JSON.parse(content.pictureurls) |
|
(5)相关内容推荐,swan页面做了判断,如果没有内容默认不显示,而相关评价却没加,自己根据需要修改。
(6)接口返回的数据包含文章的上一篇和下一篇,调用代码:
2 |
pre: content.preNext.pre, |
3 |
next: content.preNext.next, |
|
前端:
1 |
<view class= "nextpage mt10" bindtap= "nextpage" data- id = "{{pre.id}}" >上一篇:{{pre.title}}</view> |
2 |
<view class= "nextpage" bindtap= "nextpage" data- id = "{{next.id}}" >下一篇:{{next.title}}</view> |
|