欧美日韩国产一区,亚洲一区视频,色综合久久久久,私密按摩师舌头伸进去了,99re6这里只有精品,夜夜性日日交xxx性hd

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

  • • 發(fā)表于 8年前
  • • 作者 劉冰華
  • • 29418 人瀏覽
  • • 8 條評(píng)論
  • • 最后編輯時(shí)間 8年前
  • • 來自 [問 答]

原創(chuàng)聲明:本文為作者原創(chuàng),未經(jīng)允許不得轉(zhuǎn)載,經(jīng)授權(quán)轉(zhuǎn)載需注明作者和出處

小程序?yàn)榱擞脩趔w驗(yàn),所有的request均為異步請求,不會(huì)阻塞程序運(yùn)行

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

里面,

不然后出現(xiàn)返回值為空的尷尬

錯(cuò)誤代碼示例:

更改后的代碼為:

  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條評(píng)論
Ctrl+Enter
作者

劉冰華

劉冰華

APP:0 帖子:15 回復(fù):29 積分:953

已加入社區(qū)[3091]天

屌絲男士

作者詳情》
Top