(转)Proxy error: Could not proxy requestXXX from localhost:8080 to localhost:3000 (ENOTFO
问题描述:因为node服务运行在localhost:3000端口,vue运行在localhost:8080端口,不同端口存在跨域问题。
所以我使用了反向代理处理。
在vue.config.js里:
proxy:{'/api2':{target:'http://localhost:3000', changeOrigin:true, }
}
我这里是vue-cli3,所以是vue.config.js,如果是vue-cli2,就在config文件夹里的index.js里面。
在发送axios后,
toLogin(){this.axios.post('/api2/users/login',{username:this.username,password:this.password}).then((res)=>{console.log(res);}).catch((res) => {alert("错误:" + res);});
}
出现了这样的问题。
在network里面看
Proxy error: Could not proxy request /api2/users/login from localhost:8080 to localhost:3000 (ENOTFOUND).
1
解决:
1.在前端部分的项目目录里面,找到配置文件package.json
本来是这样:
"scripts": {"serve": "vue-cli-service serve","build": "vue-cli-service build"
},
给它加上start和server:
"scripts": {"serve": "vue-cli-service serve","build": "vue-cli-service build","start": "node index.js","server": "nodemon index.js --ignore client"
},
问题解决了。
导致这个问题也有可能是路径的问题
proxy代理部分:
proxy:{'/api2':{ //1target:'http://localhost:3000', //2changeOrigin:true, }
}
1.这里路径要注意
2.这里在mac和windows上写法不一样
windows:
"target": "localhost:3000"
mac:
"target": "http://127.0.0.1:3000"
发送axios部分:
this.axios.post('/api2/users/login'
/api2这个地方也要注意拼接得对不对
原文链接:https://blog.csdn.net/reagan_/article/details/97498160
(转)Proxy error: Could not proxy requestXXX from localhost:8080 to localhost:3000 (ENOTFO相关推荐
- Proxy error: Could not proxy request /admin/myResources.do from localhost.jd.com:41000 to http://loc
Proxy error: Could not proxy request /admin/myResources.do from localhost.jd.com:41000 to http://loc ...
- 运行项目报错 proxy error: could not proxy request...
今天跑项目的时候遇到一个问题,早上跑的时候还好好的,午休完起来一看,页面报错了, 弹窗提示:proxy error: could not proxy request...from 我本地 to 目标地 ...
- Proxy error: Could not proxy request /getInfo from localhost:81 to http://localhost:8080/.
Proxy error: Could not proxy request /getInfo from localhost:81 to http://localhost:8080/. 项目启动时,我的登 ...
- Proxy error: Could not proxy request XXX from XXX to XXX
先介绍一下环境,Windows10系统,vue-cli4 再直接讲结果,vue.config.js配置如下: 注意:target加上前缀http:// 因为之前Windows和Linux写法是有区别的 ...
- vue2中使用mockjs出现报错proxy error: could not proxy request xxx from xxx to xxx 和404,500问题
问题说明 出现proxy error: could not proxy request报错,应该是因为devServer代理的服务器未开启,或者地址错误,改正就好. 404 not found,找不到 ...
- Proxy error: Could not proxy request... 问题解决
背景 最近在项目中发现一个问题,每次npm run serve 时都是正常的,每次重新编译后就会有下面的提示: Proxy error: Could not proxy request Manage/ ...
- Proxy error: Could not proxy request /***/***/*** from localhost:8080 to http://000.000.000/. 的解决办法
问题概述 关于这个问题,博主是在集成联调的时候遇到的,在各个系统组件都开发完成后, 联调不通过,报错:" Proxy error: Could not proxy request /***/ ...
- Mac Proxy error: Could not proxy request
Android开发的Vue学习之路 提示:记录一些学习的知识路径,以及过程中遇到的问题 文章目录 Android开发的Vue学习之路 一.问题记录 1.Mac Proxy error: Could n ...
- proxy error: could not proxy request解决方案
找到vue.config.js文件,改地址就行: devServer: {proxy: {'/api': {target: "http://localhost:端口号自己的地址", ...
最新文章
- 零基础入门学习Python(7)-了不起的分支和循环1,2
- 【一周速递】计算机视觉/图像处理论文集
- c mysql备份还原数据库_如何备份和还原MySQL数据库?
- Rsync数据同步服务
- tf.placeholder使用错误
- 2021牛客暑期多校训练营9
- 再回首Java第二天
- 性能测试——loadrunner_添加多个主机发送请求
- jdk的安装及环境变量的配置
- Java面试宝典 Beta5.0版 (2018年最新公测版)
- 爬虫工具八爪鱼初体验
- 一个词语解释了我万千的苦闷
- PHP、Java、Python、C、C++ 这几种编程语言都各有什么特点或优点
- 个人常用观影网址记录
- hfish蜜罐搭建及简单使用
- job全异常 mapreduce_eclipse 运行MapReduce程序错误异常汇总(解决Map not fount)
- 用python可以免费下载音乐吗-使用python实现下载我们想听的歌曲,速度超快
- python爬虫requests和bs4引入
- VUE监听页面刷新和关闭事件
- C++——进入咖啡店的人数统计
热门文章
- 互联网电商新商机,亚马逊无货源模式是否真的可行?
- python学习:三目运算符
- HAL库U盘升级 STM32F407 CUBEMX:FATFS + USB_HOST + USB_OTG_FS
- 假设检验(hypothesis testing)及P值(p-value)
- prefers-color-scheme介绍
- CSR蓝牙测试仪 项目
- Arduino无线通信– NRF24L01教程
- 交易猫不显示服务器,交易猫上号器一直显示检查游戏环境
- 超宽带UWB实时精准定位,短距离无缝交互应用,物联网厘米级精度方案
- fastadmin导出