取消请求

PPG007 ... 2021-12-26 Less than 1 minute

# 取消请求

//声明变量
let cancel=null;
//配置项中添加cancelToken
axios({
    url:'http://localhost/delayTest',
    cancelToken:new axios.CancelToken(function(c){
        cancel=c
    })
})
//此时这个变量已经变成函数,调用即可取消请求
cancel()
1
2
3
4
5
6
7
8
9
10
11

Tips

一个请求对应一个 cancel 对象,调用对应的 cancel 函数即可取消请求,可以通过 setTimeout 设置超时等。

Last update: December 26, 2021 02:53
Contributors: PPG007