Vue报错: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘protocol’)
-
报错信息:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'protocol') at isURLSameOrigin (?3934:57) at dispatchXhrRequest (?b50d:145) at new Promise (<anonymous>) at xhrAdapter (?b50d:15) at dispatchRequest (?5270:58) at (?0a06:108) at wrap (?1d2b:9) at (?2b0e:5123) at eval (?56d7:17) at Module../src/ (:1134)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
-
问题原因,中引用axios区别:
import axios from “axios”;
(axios);
-
正确写法:
import axios from “axios”;
= axios;
和的区别
通过调查资料了解到:
1、不是为了vue写的插件(插件内要处理)不支持()加载方式
2、非vue官方库不支持new Vue()方式
3、每一个vue组件都是Vue的实例,所以组件内this可以拿到上添加加的属性和方法
import from "vuex"; // 官方插件vuex
(Vuex);
= axios;
- 1
- 2
- 3
主要是由于插件内部编码方式不同,axios不是按照vue规则设计的插件(准确地说不是专门为vue服务),建议用添加到vue原型链上使用;