const app = getApp()
var isLogin1=0;
Page({
data: {
userInfo: null,
isLogin:0
},
onLoad(options) {
},
chkuid() {
let id = app.globalData.user_openid
wx.cloud.callFunction({
name: 'getId',
data: {
id: id
}
})
.then(res => {
console.log("校对完毕!", res)
isLogin1= res.result.total
this.setData({
isLogin: res.result.total
})
})
.catch(res => {
console.log("校对失败!", res)
})
},
login() {
let isUser = 0
this.chkuid()
isUser = isLogin1
console.log(isUser)
isUser=this.data.isLogin
console.log(isUser)
},
})
老哥们,为啥最后我这两个log出来都是0,为啥chkuid()里的赋值没生效啊?
云函数支持这种写法吗?
你在login里面加一个setTimeOut模拟下异步赋值
云函数不是本身就支持async/await嘛
const app = getApp() var isLogin1=0; Page({ data: { userInfo: null, isLogin:0 }, onLoad(options) { }, chkuid() { let id = app.globalData.user_openid //登录核对用户ID wx.cloud.callFunction({ name: 'getWxIdChkFun', data: { id: id } }) .then(res => { console.log("校对完毕!", res) console.log("chkuid里的",res.result.total) isLogin1= res.result.total console.log("chkuid里的",isLogin1) this.setData({ isLogin: res.result.total }) console.log("chkuid里的",this.data.isLogin) }) .catch(res => { console.log("校对失败!", res) }) }, login() { let isUser = 0 this.chkuid() isUser = isLogin1 console.log('login里的isUser1',isUser) isUser=this.data.isLogin console.log('login里的isUser2',isUser) }, })