1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Vue报错: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘protocol‘)

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

时间:2021-10-26 16:53:09

相关推荐

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

问题原因,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原型链上使用;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。