axios.js 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import axios from 'axios';
  2. import {
  3. Message,
  4. MessageBox
  5. } from 'iview'
  6. const ajaxUrl = 'http://a2.aseantop.com/app';
  7. const service = axios.create({
  8. baseURL: ajaxUrl,
  9. timeout: 30000
  10. });
  11. service.title = function (title) {
  12. title = title ? title : '东盟头条—聚焦东盟 关注中国 放眼世界';
  13. window.document.title = title;
  14. };
  15. service.interceptors.response.use(
  16. response => {
  17. /**
  18. * code为非20000是抛错 可结合自己业务进行修改
  19. */
  20. const res = response;
  21. //todo 修改.现在未有token
  22. if (response.status !== 200) {
  23. Message.error({
  24. content: res.data,
  25. duration: 5 * 1000
  26. });
  27. return Promise.reject('error')
  28. } else {
  29. return response.data
  30. }
  31. },
  32. error => {
  33. Message.error({
  34. content: error.message,
  35. duration: 5 * 1000
  36. })
  37. return Promise.reject(error)
  38. }
  39. )
  40. export default service;