代码示例:
// 全局拦截器 axios.interceptors.response.use( function(response) { const data = response.data; // do something with data return data; }, function(error) { return Promise.reject(error); } );
// 发送 GET 请求 axios.get('/user') .then(function (response) { console.log(response.data); }) .catch(function (error) { console.log(error); });
// 后端返回的数据格式 { "code": 0, "data": { "username": "john", "age": 30 }, "message": "success" }
上一篇:Axios拦截器和异步加载
下一篇:Axios拦截器没有返回异常对象