问题:vue 引入 axios 报错

Vue报错: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘protocol’)

import axios from "axios";
Vue.use(axios);

解决方案:

1、不是为了vue写的插件(插件内要处理)不支持Vue.use()加载方式

2、非vue官方库不支持new Vue()方式

3、每一个vue组件都是Vue的实例,所以组件内this可以拿到Vue.prototype上添加加的属性和方法

import axios from "axios";
Vue.prototype.axios = axios;

思考总结:

继续学习

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐