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 (isURLSameOrigin.js?3934:57)
at dispatchXhrRequest (xhr.js?b50d:145)
at new Promise (<anonymous>)
at xhrAdapter (xhr.js?b50d:15)
at dispatchRequest (dispatchRequest.js?5270:58)
at Axios.request (Axios.js?0a06:108)
at wrap (bind.js?1d2b:9)
at Function.Vue.use (vue.runtime.esm.js?2b0e:5123)
at eval (main.js?56d7:17)
at Module../src/main.js (app.js:1134)
  • 问题原因,main.js中引用axios区别:
import axios from "axios";

Vue.use(axios);
  • 正确写法:
import axios from "axios";

Vue.prototype.axios = axios;

vue.use和vue.prototype的区别

通过调查资料了解到:

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

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

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

import from "vuex";		// 官方插件vuex
Vue.use(Vuex);
Vue.prototype.axios = axios;

主要是由于插件内部编码方式不同,axios不是按照vue规则设计的插件(准确地说不是专门为vue服务),建议用Vue.prototype添加到vue原型链上使用;

Vue报错: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'protocol')的更多相关文章

  1. Vue 报错Error in render: “TypeError: Cannot read properties of null (reading ‘xxx’)” found in

    前端vue报错 [Vue warn]: Error in render: "TypeError: Cannot read properties of null (reading 'name' ...

  2. vue报错 Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法

    在进行跳转的时候报错 app.js:87499 Uncaught (in promise) NavigationDuplicated?{_name: "NavigationDuplicate ...

  3. vue 报错 Uncaught (in promise) error

    可尝试在then()后加上catch() ps:该图来自网络

  4. Vue. 之 报错 Uncaught (in promise)

    Vue. 之 报错 Uncaught (in promise) 在点击同一个URL的时候,会报错如下: 解决方案: 在项目目录下运行 npm i vue-router@3.0 -S 即可.

  5. 填坑——audio不能正常播放,控制台报错 Uncaught (in promise) DOMException

    原文:https://blog.csdn.net/Mariosss/article/details/87861167 用chrome调试页面时,发现audio控件有时不能正常播放音频,控制台报错 Un ...

  6. 网页视频不能自动播放?HTML5 video报错Uncaught (in promise) DOMException解决方法

    话说发哥四年前写了一个网页,如上图效果,实际网址http://pano.z01.com ,话说做好时是正常的,突然某一天,客户说你这个网站动画不见了,这是什么原因? 结果检查脚本一切正常. 其实也不是 ...

  7. vue报错 Uncaught TypeError: Cannot read property of null

    有可能是点击a标签,但是a标签有click事件,未阻止默认事件导致报错,开始都看不出来是什么错误

  8. jQuery配合html2canvas 使用时 报错 Uncaught (in promise) Provided element is not within a Document

    报错代码: 这个函数运行时 function download(){ var element = $("#demo"); //jquery 获取元素 //这里将会报错 html2c ...

  9. vue报错Error in render: "TypeError: Cannot read property '0' of undefined"

    通常有两种情况: 1.在模板的html标签上使用length报错 vue 中使用 length判断的时候,有时会报错,如下: <div class="item_list" v ...

随机推荐

  1. 转:C++初始化成员列表

    转载至:https://blog.csdn.net/zlintokyo/article/details/6524185 C++初始化成员列表和新机制初始化表达式列表有几种用法: 1.如果类存在继承关系 ...

  2. 学习zabbix(六)

    实验环境 实验用2到2台机器,实验所用机器系统环境如下,可以看到2台机器的主机名和IP地址 ? 1 2 3 4 5 6 7 8 9 10 [root@linux-node1 ~]# cat /etc/ ...

  3. 集合流之“将List<Integer>转为String并用逗号分割”

    1.使用[流+Collectors]转换 import java.util.ArrayList; import java.util.List; import java.util.stream.Coll ...

  4. 与和或(&&和||)比较的区别

    &&(短路与)和&(逻辑与)的时候: 有假则为假,全真则为真(有假必假,全真为真) ||(短路或)和|(逻辑或)的时候: 有真则为真,全假则为假(有真必真,全假为假)

  5. 单例模式应用 | Shared_ptr引用计数管理器

    在我们模拟设计 shared_ptr 智能指针时发现,不同类型的 Shared_ptr 不能使用同一个引用计数管理器,这显然会造成内存上的浪费.因此我们考虑将其设计为单例模式使其所有的 Shared_ ...

  6. Blog Ideas

    Blog Ideas How-to Post Case Studies Product + Service Updates Product Reviews Content Survey Current ...

  7. java中的方法(method)到底怎么用?给个例子

    7.方法(method)   被调例子, int add(int x, int y){ return x+y; } 主调例子, for example: int result = add(5,3); ...

  8. Java中jdk安装与环境变量配置

    Java中jdk安装与环境变量配置 提示:下面是jdk1.7和jdk1.8的百度网盘链接 链接:https://pan.baidu.com/s/1SuHf4KlwpiG1zrf1LLAERQ 提取码: ...

  9. Reflect.has检测对象是否拥有某个属性

    Reflect.has({x: 0}, 'x'); // true Reflect.has({x: 0}, 'y'); // false // returns true for properties ...

  10. 简单的axios请求返回数据解构赋值

    本地  data.json 文件 { "name": "大熊", "age": 18, "fnc": [ 1, 2, 3 ...