vue脚手架配置代理
2024-08-30 12:25:56
vue.config.js
配置具体代理规则
module.exports = {
devServer: {
proxy: {
'/api1': { // 匹配所有以 '/api1'开头的请求路径
target: 'http://localhost:5000', // 代理目标的基础路径
changeOrigin: true,
pathRewrite: {'^/api1': ''} //访问时替换带有/api1的路径部分
},
'/student': {
target: 'http://localhost:5001',
changeOrigin: true,
pathRewrite: {'^/student': ''}
/*
访问http://localhost:8080/student/getInfo时真实访问的地址是 http://localhost:5001/getInfo
*/
}
}
}
}
/*
changeOrigin设置为true时,服务器收到的请求头中的host为:localhost:5000
changeOrigin设置为false时,服务器收到的请求头中的host为:localhost:8080
changeOrigin默认值为true
*/
说明:
- 优点:可以配置多个代理,且可以灵活的控制请求是否走代理。
- 缺点:配置略微繁琐,请求资源时必须加前缀。
最新文章
- IOS开发基础知识--碎片48
- React Native知识5-Touchable类组件
- 容器化redis高可用方案
- C语言使用cmd命令并获取输出方法
- Mysql:Error Code 1235,This version of MySQL doesn’t yet support ‘LIMIT &; IN/ALL/ANY/SOME 错误解决
- iOS学习之UI自定义cell
- delphi 取得汉字的第一个字母
- bzoj1079: [SCOI2008]着色方案
- unix 环境高级编程 读书笔记与习题解答第四篇
- stm32之ADC
- Ubuntu14.04 工作区设置
- HtmlAgilityPack实战代码
- JS滚动显示
- Git的一些操作
- Day 12 开放封闭原则,装饰器初识
- ElasticSearch核心知识总结(一)es的六种搜索方式和数据分析
- vlookup函数应用
- 第 8 章 容器网络 - 051 - 在 overlay 中运行容器
- Sorting Algorithms
- 怎么分辨是eclipse还是 android studio开发的
热门文章
- git 要求密码的解决方法:【生成gitLab公钥】:以及如何配置GitLab中的SSH key
- css3中的陌生词汇
- CF1556D-Take a Guess【交互】
- P4980-[模板]Pólya定理
- AT4518-[AGC032C]Three Circuits【欧拉回路】
- Phalcon如何创建多模块并能进行访问 《Phalcon入坑指南系列 四》
- 使用gitlab runner进行CI(三):使用sonarqube做c++的静态检查
- css新增属性之边框
- 题解 CF833D Red-Black Cobweb
- C 字符串相关的库函数