app.js里获取pages需要拿的参,使用promise处理
getlogin() {
var that = this
return new Promise(function (resolve, reject) {
wx.login({
success: (res) => {
wx.request({
url: url,
data: {},
method: 'POST',
success: (res) => {
resolve(res)
},
});
}
})
})
},
page.js里执行,因为每次都会去跑一遍promise导致接口又请求了一次,
所以判断让它没有的这个参的时候再执行
const app = getApp()
onLoad: function (options) {
if (wx.getStorageSync('sign') != '') {
this.getexpert()
this.getrecom()
} else {
app.getlogin().then(res => {
if (res.data.status == 1) {
this.getexpert()
this.getrecom()
}
})
}
},