小程序
小游戏
企业微信
微信支付
扫描小程序码分享
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
谢邀
xxx.openid 检查app.js的22行,xxx是否为undefined
--↓↓👍有用的话,点个赞吧~
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
})
},
globalData: {
openId: null,
userInfo: null,
newCommentsCount: 0,
newThumbupCount: 0,
//app.js
App({
onLaunch: function () {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init({
env: "world-ec84f7",
traceUser: true,
// 获取用户openid
let that = this;
wx.cloud.callFunction({
name: 'treeholeLogin',
complete: res => {
console.log(res.result.openid);
that.globalData.openId = res.result.openid;
if (this.openIdReadyCallback) {
this.openIdReadyCallback(res)
// console.log(res.result.openid);
console.log(res);
//that.globalData.openId = res.result.openid;
that.globalData.openId = res && res.result && res.result.openid ? res.result.openid : '';
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
谢邀
xxx.openid 检查app.js的22行,xxx是否为undefined
--↓↓👍有用的话,点个赞吧~
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
openId: null,
userInfo: null,
newCommentsCount: 0,
newThumbupCount: 0,
}
})
//app.js
App({
onLaunch: function () {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init({
env: "world-ec84f7",
traceUser: true,
})
}
// 获取用户openid
let that = this;
wx.cloud.callFunction({
name: 'treeholeLogin',
complete: res => {
console.log(res.result.openid);
that.globalData.openId = res.result.openid;
if (this.openIdReadyCallback) {
this.openIdReadyCallback(res)
}
}
})
// 获取用户信息
wx.cloud.callFunction({
name: 'treeholeLogin',
complete: res => {
// console.log(res.result.openid);
console.log(res);
//that.globalData.openId = res.result.openid;
that.globalData.openId = res && res.result && res.result.openid ? res.result.openid : '';
if (this.openIdReadyCallback) {
this.openIdReadyCallback(res)
}
}
})