//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
getUserInfo:function(cb){
var _appid = "wx9710b37de56cdccc";
var _secret ="34a3279c9517690ac9b0105d3488612c";
var that = this;
var res_data ="";
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
wx.login({
success: function (res) {
var appid = _appid;
var secret =_secret;
var code = res.code;
wx.getUserInfo({
success: function (res) {
//that.globalData.userInfo = res.userInfo
var rawData = res.rawData;
var signature = res.signature;
var encryptedData = res.encryptedData;
var iv = res.iv;
typeof cb == "function" && cb(that.globalData.userInfo)
var openid_url = 'https://wx.aa.hk/';
wx.request({
url: openid_url,
method: 'GET',
data:{
page:"login",
appid:_appid,
secret:_secret,
js_code:code,
grant_type:"authorization_code",
rawData:rawData,
signature:signature,
iv:iv,
encryptedData:encryptedData
},
success: function(res){
res_data = res.data;
that.globalData.userInfo =res_data;
}
});
}
})
}
})
}
},
globalData:{
userInfo:null
}
})
设置后:
that.globalData.userInfo =res_data;
外部console是null
求教 wx.request 后要怎么赋值给
globalData:{userInfo:null} 也全局调用呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你确定执行到赋值那行代码了?
我也遇到这个问题,单步APP.JS后发现,程序启动时,貌似会跳过网络请求后给globaldata的赋值