index.js 755 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import axios from "axios"
  2. import { useGlobalState } from '../store/index'
  3. const state = useGlobalState()
  4. const service = axios.create({
  5. baseURL: 'https://10.83.240.193:8090/digitalTwain',
  6. timeout: 60000, // 请求超时时间 毫秒
  7. // withCredentials: true,
  8. headers: {
  9. "Content-Type": "application/json",
  10. },
  11. })
  12. service.interceptors.request.use(
  13. (config) => {
  14. // config.data.token = state.token.value
  15. return config;
  16. },
  17. (error) => {
  18. return Promise.reject(error);
  19. }
  20. )
  21. service.interceptors.response.use(
  22. (response) => {
  23. const res = response.data;
  24. if (res!==null && res!=undefined)
  25. {
  26. return res;
  27. }else {
  28. console.log("请求出现错误")
  29. }
  30. },
  31. (error) => {
  32. return Promise.reject(error);
  33. }
  34. )
  35. export default service;