axios.js 540 B

12345678910111213141516171819202122
  1. /* eslint-disable no-console */
  2. /* eslint-disable no-param-reassign */
  3. import Vue from 'vue';
  4. import AxiosWrapper from '../utils/axios-wrapper';
  5. const Plugin = {
  6. install(vue, options) {
  7. // 3. 注入组件
  8. vue.mixin({
  9. created() {
  10. if (this.$store && !this.$store.$axios) {
  11. this.$store.$axios = this.$axios;
  12. }
  13. },
  14. });
  15. // 4. 添加实例方法
  16. vue.prototype.$axios = new AxiosWrapper(options);
  17. },
  18. };
  19. Vue.use(Plugin, { baseUrl: process.env.VUE_APP_AXIOS_BASE_URL, unwrap: true });