接口標(biāo)識(shí):show
接口url:https://你的網(wǎng)站/api/index.php?action=show[&id=10]
接口參數(shù):

小程序代碼
02 |
url: app.globalData.api + "action=show" , |
04 |
typeid: that.data.typeid, |
06 |
relation: 1,//開啟調(diào)用相關(guān)推薦 |
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'),里邊封裝的有對(duì)時(shí)間的處理,因?yàn)閍pi返回的是時(shí)間戳,需要處理
1 |
content.relations[i].pubdate = util.formatTime(content.relations[i].pubdate, 'Y-M-D' ); |
|
(2)由于小程序不支持直接的html標(biāo)簽,所以引入bdparse插件,具體參考demo。
(3)relation默認(rèn)關(guān)閉,需要修改代碼來開啟,參考demo
(4)字段中如果有數(shù)組,需要進(jìn)行特殊處理,代碼實(shí)例:
2 |
if (content.pictureurls){ |
3 |
content.pictureurls = JSON.parse(content.pictureurls) |
|
(5)相關(guān)內(nèi)容推薦,swan頁面做了判斷,如果沒有內(nèi)容默認(rèn)不顯示,而相關(guān)評(píng)價(jià)卻沒加,自己根據(jù)需要修改。
(6)接口返回的數(shù)據(jù)包含文章的上一篇和下一篇,調(diào)用代碼:
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> |
|