此代码取消GET请求但不能中止POST调用.
如果我首先发送GET请求并且我不通过abortAll方法取消它们,他们只是自己完成这个令牌自己取消并且不能在下一个请求中工作?我错过了什么?谢谢,约翰
import axios from 'axios'
class RequestHandler {
constructor(){
this.cancelToken = axios.CancelToken;
this.source = this.cancelToken.source();
}
get(url,callback){
axios.get(url,{
cancelToken:this.source.token,
}).then(function(response){
callback(response.data);
}).catch(function(err){
console.log(err);
})
}
post(url,callbackOnSuccess,callbackOnFail){
axios.post(url,{
cancelToken:this.source.token,
}).then(function(response){
callbackOnSuccess(response.data);
}).catch(function(err){
callbackOnFail()
})
}
abortAll(){
this.source.cancel();
// regenerate cancelToken
this.source = this.cancelToken.source();
}
}
Run Code Online (Sandbox Code Playgroud)