axios.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. import Vue from 'vue';
  3. import axios from "axios";
  4. // Full config: https://github.com/axios/axios#request-config
  5. // axios.defaults.baseURL = 'http://120.55.70.156:80/api';
  6. axios.defaults.baseURL = 'http://10.108.34.2:80'; //向日葵'
  7. // axios.defaults.baseURL = 'http://172.16.120.104:8089';
  8. // axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || 'http://120.55.70.156:80/api';
  9. // axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
  10. // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  11. let config = {
  12. // baseURL: process.env.baseURL || process.env.apiUrl || "",
  13. // timeout: 60 * 1000, // Timeout
  14. // withCredentials: true, // Check cross-site Access-Control
  15. };
  16. const _axios = axios.create(config);
  17. _axios.interceptors.request.use(
  18. function(config) {
  19. // Do something before request is sent
  20. return config;
  21. },
  22. function(error) {
  23. // Do something with request error
  24. return Promise.reject(error);
  25. }
  26. );
  27. // Add a response interceptor
  28. _axios.interceptors.response.use(
  29. function(response) {
  30. // Do something with response data
  31. return response.data;
  32. },
  33. function(error) {
  34. // Do something with response error
  35. return Promise.reject(error);
  36. }
  37. );
  38. Plugin.install = function(Vue, options) {
  39. console.log(options)
  40. Vue.axios = _axios;
  41. window.axios = _axios;
  42. Object.defineProperties(Vue.prototype, {
  43. axios: {
  44. get() {
  45. return _axios;
  46. }
  47. },
  48. $axios: {
  49. get() {
  50. return _axios;
  51. }
  52. },
  53. });
  54. };
  55. Vue.use(Plugin)
  56. export default Plugin;