接口標識: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> |
|