打印app是ve {onLaunch: ƒ, onShow: ƒ, onHide: ƒ, onUnlaunch: ƒ}
而且代码全部是对的
onLoad: function () {
console.log(app)
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
//hasUserInfo: true
})
} else if (this.data.canIUse){
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
//hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
//hasUserInfo: true
})
}
})
}
},
getUserInfo: function(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
console.log(e.detail.userInfo)
if(e.detail.userInfo){
wx.login({
success: (res) => {
console.log(res.code)
//获取openid
wx.request({
url: app.globalData.webJavaserver+'wxlogin/login?code=&nickname=' + e.detail.userInfo.nickName,
header:{
"content-type": "application/json"
},
success(res){
//保存userId
app.globalData.openid = rea.data;
console.log(app.globalData.openid)
//路由跳转
wx.switchTab({
url: '/pages/index/index',
})
}
})
},
})
}else{
wx.showModal({
title: '提示',
content: "你将无法正常使用"
})
}
this.setData({
userInfo: e.detail.userInfo,
//hasUserInfo: true
})
},
请问有大神知道是怎么肥事吗?
w我终于直到怎么回事了,emmmm...我把文件一个一个复制过去,然后发现有一个js页面写成了const app = new App(),
z找了一下午一晚上啊啊啊啊,应该写成const app = getApp(),所有页面都是,这样才能获取到数据,我真的。。。太难了
顶一下,虽然不知道有没有用