使用场景
- bug: tab切换,当点击tab2时,由于接口反应比较慢,在数据返回之前切换tab,会造成tab2的数据会拼接在切换后的tab列表下面
- 解决方法:在tab切换时,取消未完成的接口请求
getList() {
this.status == 'loading'
this.req = uni.request({
url: baseUrl + '/api/userOrder',
data: {
page: this.page,
order_status: this.tab == 0 ? 0 : this.tab == 1 ? 3 : -1
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Authorization': uni.getStorageSync('token') || ''
},
method: "get",
success: (res) => {
let data = res.data.data
if (data.length < 10) {
this.status = 'nomore'
} else {
this.status = 'loadmore'
}
this.list = this.list.concat(data)
uni.stopPullDownRefresh();
},
})
},
change(index) {
this.req.abort()
this.tab = index;
this.page = 1
this.status = 'loadmore',
this.list = []
this.getList()
},