axios问题
RoleTang 4/12/2022
axios
是一个基于promise
的网络请求库,可以用于nodejs和浏览器中。在nodejs
使用的是原生http
模块,在浏览器中使用的是XMLHttpRequest
。
拦截器
可以设置
全局拦截器。
实例拦截器
也可以指定单个方法的请求拦截器
即是自己配置,在发送某个请求之前查看配置中是否有interceptor,有的话调用一次
如何取消请求
AbortController接口
abort(流产)
const controller = new AbortController(); axios.get('/foo/bar', { // 需要传递一个signal signal: controller.signal }).then(function(response) { //... }); // 取消请求 controller.abort()
以前使用的是
cancelToken
,现在已经废弃