Open into-piece opened 3 years ago
cancelToken 底部原理是xmlHttpRequest 的abort
拦截器有对应request和response的设置,request设置发起的请求统一加上token的自定义header
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
config.headers.token = 'added by interceptor';
return config;
});
// 添加响应拦截器
axios.interceptors.response.use(function (data) {
data.data = data.data + ' - modified by interceptor';
return data;
});