首先,在page外定义一个公共函数用于发送获取位置的请求 var getLocation = function (that) { wx.getLocation({ type: 'wgs84', success: function (res) { // 经纬度 var latitude = res.latitude var longitude = res.longitude var aK = that.data.aK wx.request({ url: 'https://api.map.baidu
小程序为了用户体验,所有的request均为异步请求,不会阻塞程序运行 百牛信息技术bainiu.ltd整理发布于博客园 所以当你需要同步请求,锁死操作时,最好将所有的逻辑写在success:function(){} 里面, 不然后出现返回值为空的尴尬 错误代码示例: 更改后的代码为: onShow:function(){ // 页面显示 var commonFunction = require('../../pages/index/common'), that = this; var inte