axios.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 = process.env.baseURL || process.env.apiUrl || '';
  6. // axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
  7. axios.defaults.baseURL = 'http://121.40.217.77:8082';
  8. // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  9. let config = {
  10. // baseURL: process.env.baseURL || process.env.apiUrl || ""
  11. // timeout: 60 * 1000, // Timeout
  12. // withCredentials: true, // Check cross-site Access-Control
  13. };
  14. const _axios = axios.create(config);
  15. _axios.interceptors.request.use(
  16. function(config) {
  17. // Do something before request is sent
  18. return config;
  19. },
  20. function(error) {
  21. // Do something with request error
  22. return Promise.reject(error);
  23. }
  24. );
  25. // Add a response interceptor
  26. _axios.interceptors.response.use(
  27. function(response) {
  28. // Do something with response data
  29. return response.data;
  30. },
  31. function(error) {
  32. // Do something with response error
  33. return Promise.reject(error);
  34. }
  35. );
  36. Plugin.install = function(Vue, options) {
  37. console.log(options)
  38. Vue.axios = _axios;
  39. window.axios = _axios;
  40. Object.defineProperties(Vue.prototype, {
  41. axios: {
  42. get() {
  43. return _axios;
  44. }
  45. },
  46. $axios: {
  47. get() {
  48. return _axios;
  49. }
  50. },
  51. });
  52. };
  53. Vue.use(Plugin)
  54. export default Plugin;