小程序初始化时触发App里的onLaunch,后面再执行页面Page里的onLoad或onShow,但是在onLaunch里执行用户登录,等待返回值的时候Page里的onLoad或onShow事件就已经执行了。
原代码段
app.js代码片
.
globalData = {
userInfo: null,
token:''
}
onLaunch() {
this.$interceptors = {
request: {
config(p) {
p.url = 'http://test.xxx.com/api' + p.url
if(this.globalData.token && this.globalData.token != ''){
p.header = {
token: this.globalData.token
};
}
return p;
},
success(rst) {
return rst;
}
}
};
this.login();
}
login() {
const self = this;
wx.login({
success(data) {
wepy.request