读axios的api是发现axios提供了ajax取消的机制。
var CancelToken = axios.CancelToken;
var source;
function reqData(){
if(srouce) source.cancel("旧的请求被新的请求覆盖")
source = CancelToken.source();
axios.get('/user/12345', {
cancelToken: source.token
})
.catch(function(thrown) {
if (axios.isCancel(thrown)) {
console.log('Request canceled', thrown.message);
} else {
// handle error
}
});
}
reqData();
reqData();
reqData();
网友评论