wx.login({
success(res) {
//发起网络请求
wx.cloud.callFunction({
name: 'login'
}).then(res => console.log(res)).then(db.collection('zhongdui').add({
data: {
openid: res.result
}
})).then(
kkid = res.result,
)
}
})
其中kkid为全局变量,函数运行后kkid的值为undefined
wx.login({
success(res) {
//发起网络请求
wx.cloud.callFunction({
name: 'login'
}).then(res => console.log(res)).then(db.collection('zhongdui').add({
data: {
openid: res.result
}
})).then(
kkid = res.result,
)
}
})
其中kkid为全局变量,函数运行后kkid的值为undefined
wx.login({
success(res) {
//发起网络请求
wx.cloud.callFunction({
name: 'login'
}).then(res2 => {
console.log(res2)
kkid = res.result
return db.collection('zhongdui').add({
data: {
openid: res.result
}
})
})
}
})
如果要在wx.login之外能打印kkid 值,还需配合async / await 使用
你那么写,第二个和第三个then里res是不存在的
楼上好厉害,