wx.setStorageSync('token', openid) wx.getStorageSync("token") 这个有问题吗? 这几天一直传输给后台数据丢失
wx.login({
success: res => {
wx.request({
url: app.globalData.url + 'login/authorization',
method: 'post',
data: {
code: res.code,
},
success: res => {
if (res.data.code == 200) {
wx.setStorageSync('token', res.data.token)
that.onGetData();
} else {
wx.showToast({
title: '发生错误,正在重试',
icon: 'none',
duration: 2000
});
setTimeout(() => {
that.onShow();
}, 3000);
}
}
});
}
})
var that = this;
wx.request({
url: app.globalData.url + 'Index/school',
method: 'POST',
data: {
token: wx.getStorageSync("token"),
keyword: that.data.keyword,
page: that.data.page,
},
success: (res) => {
// console.log(res)
if (res.data.code === 200) {
const newList = res.data.data.data || [];
const list = that.data.page === 1 ? newList : [...that.data.list, ...newList];
that.setData({
list: list,
hasMore: res.data.data.has_more,
page: res.data.data.has_more == true ? that.data.page + 1 : false,
});
} else {
wx.showToast({
title: res.data.msg || '加载失败',
icon: 'none'
});
}
},
fail: (err) => {
that.onShow()
wx.removeStorageSync('token');
wx.showToast({
title: '网络请求失败',
icon: 'none'
});
},
complete: () => {
wx.hideLoading();
}
});
前面几千人使用都没问题

两个请求都是异步的,第二个请求(Index/school)有可能发生在第一个前面。
流程没走下去呗,浅尝辄止
应该是执行顺序的问题,你第二个方法获取的时候,第一个方法还没有返回数据