微信開發之小程序開發網絡請求(表單提交等)

官網地址:https://developers.weixin.qq.com/miniprogram/dev/api/wx.request.html

網絡請求使用的是微信的request

下面貼上網絡請求實現的代碼

method:支持POST GET PUT DELETE

表單提交設置:'Content-Type':application/x-www-form-urlencoded

/**
   * 請求網絡獲取列表數據
   */
  getList() {
    var that = this;
    //顯示微信加載圈
    wx.showLoading({})
    //這裏調用微信的request請求傳入url、設置請求方式、可以傳輸data參數、設置請求頭、後面就是可以處理成功和失敗的時候的業務
    wx.request({
      url: app.globalData.apiHost + '/getfoodList',
      method: 'GET',
      data: {},
      header: {
        'Accept': 'application/json'
      },
      success: function(res) {
        console.log(res.data.data);
        that.setData({
          dataShow: res.data.data,
          total: res.data.data && res.data.data.length > 0 ? res.data.data.length : 0,
        })
        //對微信加載圈進行隱藏
        wx.hideLoading();
      },fail: function(res) {

      }
    })
  },

下圖中你看的showLoading是加載圈可以設置加載圈的title等信息、不設置就顯示一個加載的效果、同微信加載效果

 wx.showLoading({})

 wx.showLoading({
      title: '',
      mask: true,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章