应用场景
用户需要快速请求,比如抢购,前一次的请求数据是毫无意义的,直接取消就完事了快速切换tab等操作菜单后,如果前一次请求比后一次请求响应慢,数据就会对不上
Axios中的使用
this.cancel && this.cancel('message')
this.$axios({
url,
method,
cancelToken: new this.$axios.CancelToken(c => {
this.cancel = c
})
})
axios.interceptors.response.use(
res => res,
err => {
!err.toString().includes('Cancel') && Vue.prototype.$message.error(`网络请求错误: ${err}`)
return Promise.reject(err)
}
)
以前的方案
把操作按钮冻结,不给操作,但使用体验偶尔会很糟糕
转载请注明原文地址:https://ipadbbs.8miu.com/read-27462.html