问题原因,main.js中引用axios区别:
import axios from "axios";Vue.use(axios);
正确写法:
import axios from "axios";Vue.prototype.axios = axios;
通过调查资料了解到:
1、不是为了vue写的插件(插件内要处理)不支持Vue.use()加载方式
2、非vue官方库不支持new Vue()方式
3、每一个vue组件都是Vue的实例,所以组件内this可以拿到Vue.prototype上添加加的属性和方法
import from "vuex";// 官方插件vuexVue.use(Vuex);Vue.prototype.axios = axios;
主要是由于插件内部编码方式不同,axios不是按照vue规则设计的插件(准确地说不是专门为vue服务),建议用Vue.prototype添加到vue原型链上使用;