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
*/

说明:

  1. 优点:可以配置多个代理,且可以灵活的控制请求是否走代理。
  2. 缺点:配置略微繁琐,请求资源时必须加前缀。

最新文章

  1. IOS开发基础知识--碎片48
  2. React Native知识5-Touchable类组件
  3. 容器化redis高可用方案
  4. C语言使用cmd命令并获取输出方法
  5. Mysql:Error Code 1235,This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME 错误解决
  6. iOS学习之UI自定义cell
  7. delphi 取得汉字的第一个字母
  8. bzoj1079: [SCOI2008]着色方案
  9. unix 环境高级编程 读书笔记与习题解答第四篇
  10. stm32之ADC
  11. Ubuntu14.04 工作区设置
  12. HtmlAgilityPack实战代码
  13. JS滚动显示
  14. Git的一些操作
  15. Day 12 开放封闭原则,装饰器初识
  16. ElasticSearch核心知识总结(一)es的六种搜索方式和数据分析
  17. vlookup函数应用
  18. 第 8 章 容器网络 - 051 - 在 overlay 中运行容器
  19. Sorting Algorithms
  20. 怎么分辨是eclipse还是 android studio开发的

热门文章

  1. git 要求密码的解决方法:【生成gitLab公钥】:以及如何配置GitLab中的SSH key
  2. css3中的陌生词汇
  3. CF1556D-Take a Guess【交互】
  4. P4980-[模板]Pólya定理
  5. AT4518-[AGC032C]Three Circuits【欧拉回路】
  6. Phalcon如何创建多模块并能进行访问 《Phalcon入坑指南系列 四》
  7. 使用gitlab runner进行CI(三):使用sonarqube做c++的静态检查
  8. css新增属性之边框
  9. 题解 CF833D Red-Black Cobweb
  10. C 字符串相关的库函数