直接写上我的部分代码和我期待的效果,请各路大神帮忙解答下
function(){
var bl = this.openLogin()
//因为是wx.request是异步 ,所以这里的bl还没有赋值 请问我该怎么写?
if (bl) {
} else {
}
}
openLogin:function(){
var _this = this;
wx.request({
url: getApp().globalData.ctPath,
data: {
wxOpenid: _this.globalData.openid
},
header: getApp().globalData.header,
success: function (res) {
if (res.data.user != null) {
return true;
}else{
return false;
}
}
})
}
这是修改后的代码,你试试
openLogin:function(){
var _this = this;
const demo=
new
Promise((resolve, reject) => {
wx.request({
url: getApp().globalData.ctPath,
data: {
wxOpenid: _this.globalData.openid
},
header: getApp().globalData.header,
success: function (res) {
resolve(res)
}
})
})
demo.then(res=>{
if (res.data.user != null) {
return true;
}else{
return false;
}
})
}