wx.request(OBJECT)發起的是https請求。一個微信小程序,同時只能有5個網絡請求連接。
OBJECT參數說明:
效果圖:
net.js
Page({ data:{ result:{}, }, onLoad:function(options){ this.getDate('http://baobab.wandoujia.com/api/v2/feed?num=2'); }, /** * 網絡請求的函數:接收一個URL參數 */ getDate:function(URL){ var that = this; // 申請一個網絡請求 wx.request({ url:URL, method:'GET', //添加data // data: { // x: '', // y: '' // }, //添加頭信息 // header: { // 'Content-Type': 'application/json' // }, // 請求成功的回調 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}}個列表</Text> <block wx:for-items="{{item.itemList}}"> <image style="width:100%;height:200px;" src="{{item.data.cover.feed}}"></image> </block></block>
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答