axios拦截器
1、请求拦截器 在请求发出之前设置一些信息
axios.interceptors.request.use(function(config) {
console.log(config.url);
config.headers.mytoken = 'nihao'; // 设置请求头
return config;
}, function(error) {
console.log(error);
});
axios.get('http://localhost:3000/adata').then(function(res) {
console.log(res.data);
})
2、响应拦截器 再获取数据之前对数据进行一些加工处理
axios.interceptors.response.use(function(res) {
var data = res.data
return data;
}, function(error) {
console.log(error);
});
axios.get('http://localhost:3000/adata').then(function(res) {
console.log(res);
})

浙公网安备 33010602011771号