res.data是找得到的,然后我想判断数据库里有这条记录就可以继续,没有就跳转到首页去。用if判断的,为什么直接跳过if步骤没有执行呢?求大佬解释。
调用数据库后if语句怎么直接跳过了?Why is the if statement skipped directly after calling the database?
调用数据库后if语句怎么直接跳过了?res.data是找得到的,然后我想判断数据库里有这条记录就可以继续,没有就跳转到首页去。用if判断的,为什么直接跳过if步骤没有执行呢?求大佬解释。
res.data I can find it. Then I want to judge if there is this record in the database, I can continue. If there is no record, I will jump to the home page. Judging by if, why did you skip the if step and not execute it? Please explain.
回答:
author不是有数据?你if判断条件不成立当然不会执行里面的代码了。
onLoad: function (options) {
that = this
wx.cloud.callFunction({
name: 'login'
}).then(res => {
var openid=res.result.openid
db.collection('user').doc(openid).get({
success: function(res) {
console.log(res.data[0].author)
if(res.data[0].author==''){
wx.showToast({
title: '请先获取信息',
icon: 'success',
duration: 2000,
})
wx.switchTab({
url: '/pages/list/list'
});}else{console.log('信息存在');}
}
})
that.setData({
openid: openid})
console.log(openid)
}),
that.jugdeUserLogin()
},
原文出处:调用数据库后if语句怎么直接跳过了?
有信息所以不进if