这是修改后的代码,你试试 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; } }) }
求教 promise怎么用直接写上我的部分代码和我期待的效果,请各路大神帮忙解答下 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; } } }) }
2018-07-09