源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

微信小程序 网络请求API详解

  • 时间:2021-12-29 16:56 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:微信小程序 网络请求API详解
wx.request(OBJECT)发起的是https请求。一个微信小程序,同时只能有5个网络请求连接。 OBJECT参数说明: [img]http://files.jb51.net/file_images/article/201610/2016102594803105.png?201692594818[/img]  效果图: [img]http://files.jb51.net/file_images/article/201610/2016102594835592.gif?201692594852[/img]  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>

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部