axios.js 452 B

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