小程序为了用户体验,所有的request均为异步请求,不会阻塞程序运行
百牛信息技术bainiu.ltd整理发布于博客园
所以当你需要同步请求,锁死操作时,最好将所有的逻辑写在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);}});},此文作用仅为填坑,