request.js 890 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import axios from "axios";
  2. // 创建实例
  3. // Set config defaults when creating the instance
  4. const instance = axios.create({
  5. baseURL: 'https://official.webapi.bicredit.xin/api/',//直接使用博客链接
  6. timeout: 2500,
  7. });
  8. // 添加请求拦截器
  9. instance.interceptors.request.use((config) => {
  10. // 在发送请求之前做些什么
  11. console.log('config', config);
  12. return config;
  13. }, function (error) {
  14. // 对请求错误做些什么
  15. return Promise.reject(error);
  16. });
  17. // 添加响应拦截器
  18. instance.interceptors.response.use((response) => {
  19. // 对响应数据做点什么
  20. console.log('response', response);
  21. // const {
  22. // config,
  23. // data,
  24. // headers,
  25. // request,
  26. // status,
  27. // statusText
  28. // } = response
  29. return response;
  30. }, function (error) {
  31. // 对响应错误做点什么
  32. return Promise.reject(error);
  33. });
  34. export default instance