Vue跨域问题解决
2024-09-03 06:39:40
项目根目录下创建vue.config.js
module.exports = {
devServer: {
proxy: {
//配置跨域
'/api': {
//这里是真实的后台接口
target: 'https://localhost:5001/',
//允许跨域
changeOrigin: true,
//重写路径
pathRewrite: {
/*
浏览器中看到请求的地址为:http://localhost:8080/api/region
实际上访问的地址是:https://localhost:5001/api/region
如果请求中不存在/api则设置为'^/api': '',
*/
'^/api': '/api',
},
},
},
},
}
设置为'^/api': ''所有的请求中如果不是/api/开始的请求也需要写上会自动替换成后边的值
配置完成后需要重新启动vue项目
最新文章
- webapi的学习资料
- 常见ES6新属性
- 原始感知机入门——python3实现
- 共享业务稳定性测试&;技术创新组
- ackerman递归
- android stuido 在线安装svn插件,添加版本库无响应
- [转]Android重力感应开发
- 11gOCP 1z0-052 :2013-09-11 MGR_ROLE role........................................................A66
- 第二次项目冲刺(Beta阶段)5.25
- Git基本命令 -- 创建Git项目
- vue 双向数据绑定原理
- throws与throw
- bzoj1741 [Usaco2005 nov]Asteroids 穿越小行星群 最小点覆盖
- Liunx 硬盘分区
- Centos 7 安装 PostgreSQL PGAdmin4
- win7X64位安装mysql-5.7.16
- 软件工程课程设计——第一个Spring
- Anfroid 在界面中显示图片 ImageView
- Hive之 hive架构
- 如何修改TFS 2013中工作项附件大小限制
热门文章
- Bugku-web-web8
- Bypass D盾 Webshell
- 【LeetCode】169. 多数元素
- VScode安装配置
- 去掉文件中的^M
- spring-security oauth2.0简单集成
- Redis奇怪的姿势
- Charles 抓包 Client SSL handshake failed - Remote host closed connection during handshake
- 伪静态是什么?伪静态与普通html静态网页区别?
- .Net Core WebApi(三)--使用 IdentityServer4 4.1.1 踩坑记录