微信小程序在真机调试上无法弹窗获取信息,但是在编译器里可以正常显示
编译器
真机调试,点击后直接就登录成功了
```c
getLoginUser: function() {
wx.showLoading({
title: "正在登录...",
mask: true
})
wx.getUserProfile({
desc: "获取用户相关信息",
success: res => {
if(res.errMsg === "getUserProfile:ok") {
let username = res.userInfo.nickName;
let headPic = res.userInfo.avatarUrl;
wx.login({
success: async res => {
if (res.errMsg === "login:ok") {
// 调用后端接口,验证用户数据
const response = await myRequest({
url: api.BASE_URL + "/app/user/wx_login",
method: "POST",
data: {
wxHeadPic: headPic,
wxUsername: username,
code: res.code
}
});
if(response.data.code === 0) {
Notify({ type: "success", message: response.data.msg, duration: 1000 });
Cache.setCache(getApp().globalData.SESSION_KEY_LOGIN_USER, response.data.data.token, 3600);
this.setData({
userInfo: response.data.data,
editUser: response.data.data,
isLogin: true
});
} else {
Notify({ type: "danger", message: response.data.msg, duration: 2000 });
}
} else {
wx.showToast({
icon: "error",
title: "登录失败"
});
}
wx.hideLoading();
},
fail: res => {
wx.showToast({
icon: "error",
title: "登录失败"
});
wx.hideLoading();
}
})
} else {
wx.showToast({
icon: "error",
title: "获取用户失败"
});
wx.hideLoading();
}
},
fail: res => {
wx.showToast({
icon: "error",
title: "获取用户失败"
});
wx.hideLoading();
}
})
},