axios新方式中断请求
文档:GitHub - axios/axios: Promise based HTTP client for the browser and node.js

官网的示例
const controller = new AbortController();
axios.get('/foo/bar', {
signal: controller.signal
}).then(function(response) {
//...
});
// cancel the request
controller.abort()
如果按照这种方法后,再次点请求就无法发送了,因为signal里面的属性aborted是只读属性,改不了,你点击发送请求,他会读取signal的aborted值为true,就不发送了,咋办?看下去
我看了一下api,文档:AbortSignal - Web API 接口参考 | MDN,

当使用AbortController在axios中中断请求后,由于其signal的aborted属性变为只读,导致无法再次发送请求。解决方法是将AbortController实例定义在外部,并在每次请求前检查是否存在上一个请求,如果存在则取消并重置,从而实现多次中断和发送请求的功能。
最低0.47元/天 解锁文章
8053

被折叠的 条评论
为什么被折叠?



