request.js 568 B

12345678910111213141516171819202122
  1. // htmll里面已经引入了axios
  2. const instance = axios.create({});
  3. // 添加请求拦截器
  4. instance.interceptors.request.use(function (config) {
  5. // 在发送请求之前做些什么
  6. return config;
  7. }, function (error) {
  8. // 对请求错误做些什么
  9. return Promise.reject(error);
  10. });
  11. // 添加响应拦截器
  12. instance.interceptors.response.use(function (response) {
  13. // 对响应数据做点什么
  14. return response.data;
  15. }, function (error) {
  16. // 对响应错误做点什么
  17. return Promise.reject(error);
  18. });
  19. export default instance