axios.ts 606 B

123456789101112131415161718192021222324252627282930
  1. import axios from "axios";
  2. // axios默认配置
  3. axios.defaults.headers.post["Content-Type"] = "application/json,charset=utf-8";
  4. axios.defaults.timeout = 1000 * 60 * 60 * 24;
  5. axios.defaults.baseURL = "/";
  6. //添加请求拦截器
  7. axios.interceptors.request.use(
  8. (config: any) => {
  9. //config.data config.params config.headers
  10. return config;
  11. },
  12. (error: any) => {
  13. return Promise.reject(error);
  14. }
  15. );
  16. // 添加响应拦截器
  17. axios.interceptors.response.use(
  18. (response: any) => {
  19. return response;
  20. },
  21. (error: any) => {
  22. return Promise.reject(error);
  23. }
  24. );
  25. export default axios;