老司机三级_天天干天天操天天爽_女人被爽到娇喘呻吟视频_久久国产精品99久久久大便 - 亚洲日本系列

小程序不支持wx.request同步請求解決方法

  • • 發表于 9年前
  • • 作者 劉冰華
  • • 29509 人瀏覽
  • • 8 條評論
  • • 最后編輯時間 9年前
  • • 來自 [問 答]

原創聲明:本文為作者原創,未經允許不得轉載,經授權轉載需注明作者和出處

小程序為了用戶體驗,所有的request均為異步請求,不會阻塞程序運行

所以當你需要同步請求,鎖死操作時,最好將所有的邏輯寫在success:function(){}

里面,

不然后出現返回值為空的尷尬

錯誤代碼示例:

更改后的代碼為:

  onShow:function(){
    // 頁面顯示

    var commonFunction = require('../../pages/index/common'),
        that = this;

    var interval = setInterval(function(){
        that.setData({
          nowTime : commonFunction.formatTime(new Date())
        })
    },1000);
    var request = function(latitude,longitude){
        wx.request({
            url:  that.globalData.API_URL + 'getLocation',
            data: {
                latitude : latitude,
                longitude : longitude
            },
            method: 'GET', 
            success: function(res){
                let result = res.data.data;
                result = JSON.parse(result);
                console.log(result);
            }
            });
    };
     wx.getLocation({
          "type" : 'gcj02',
          "success" : function(res){
              const latitude = res.latitude;
              const longitude = res.longitude;
              request(latitude,longitude);
          },
          "fail" : function(e){
              console.log(e);
          }
      });



  },


  此文作用僅為填坑,
分享到:
8條評論
Ctrl+Enter
作者

劉冰華

劉冰華

APP:0 帖子:15 回復:29 積分:953

已加入社區[3205]天

屌絲男士

作者詳情》
Top