wx.request(OBJECT)發(fā)起的是https請(qǐng)求丘损。一個(gè)微信小程序旦万,同時(shí)只能有5個(gè)網(wǎng)絡(luò)請(qǐng)求連接修己。
OBJECT參數(shù)說明:
效果圖:
示例代碼:
net.js
Page({
data:{
result:{},
},
onLoad:function(options){
this.getDate('http://baobab.wandoujia.com/api/v2/feed?num=2');
},
/**
* 網(wǎng)絡(luò)請(qǐng)求的函數(shù):接收一個(gè)URL參數(shù)
*/
getDate:function(URL){
var that = this;
// 申請(qǐng)一個(gè)網(wǎng)絡(luò)請(qǐng)求
wx.request({
url:URL,
method:'GET',
//添加data
// data: {
// x: '',
// y: ''
// },
//添加頭信息
// header: {
// 'Content-Type': 'application/json'
// },
// 請(qǐng)求成功的回調(diào)
success: function(res) {
that.setData({
result:res.data
})
console.log(res.data)
}
})
},
})
net.wxml:
<block wx:for-items="{{result.issueList}}">
<Text style="color:green;">第{{index+1}}個(gè)列表</Text>
<block wx:for-items="{{item.itemList}}">
<image style="width:100%;height:200px;" src="{{item.data.cover.feed}}"></image>
</block>
</block>
來源:http://bbs.520it.com/forum.php?mod=viewthread&tid=2535&extra=page%3D1