浙里学车工行支付宝生活号支付收银台项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

  1. /**
  2. * axios配置
  3. */
  4. import Vue from 'vue'
  5. import axios from 'axios'
  6. import VueAxios from 'vue-axios'
  7. import setting from './setting'
  8. import cookies from 'vue-cookies';
  9. import { Dialog } from 'vant';
  10. import router from '@/router'
  11. Vue.use(VueAxios, axios);
  12. //axios.defaults.baseURL = setting.baseURL;
  13. axios.defaults.baseURL =setting.context_path;
  14. axios.defaults.headers.common[setting.tokenHeaderName] ='';
  15. axios.interceptors.request.use((config ) => {
  16. var url=config.url;
  17. if (url.indexOf("?")!=-1) {
  18. let queryString = url.split('?')[1] // code=12313123&a=444
  19. if (queryString) {
  20. let query = queryString.split('&')
  21. for (let i = 0; i < query.length; i++) {
  22. let arr = query[i].split('=')
  23. if(arr[0]=="token"){
  24. config.headers[setting.tokenHeaderName] =arr[1];
  25. break;
  26. }
  27. }
  28. }
  29. }
  30. return config;
  31. }, (error) => {
  32. return Promise.reject(error);
  33. });
  34. /* 响应拦截器 */
  35. axios.interceptors.response.use((res) => {
  36. return res;
  37. }, (error) => {
  38. return Promise.reject(error);
  39. });