关于vue.config.js 的 proxy 配置
有的同学不怎么明白项目里面有的配置了 pathRewrite 地址重写,有的又没有进行配置?
/*
* proxy代理配置的说明
* *接口例子:/zy-server/sms/captcha
*
* 1.没有配置地址重写 pathRewrite:
* proxy: {
'/zy-server': {
target: 'http://localhost:5220', //测试环境
},
},
* proxy: 'http://localhost:5220' //也可以这样写
*
* 比如: http://localhost:8081/zy-server/sms/captcha
会被转发到 http://localhost:5220/zy-server/sms/captcha //浏览器是看不到的
*
* 2.配置有 地址重写 pathRewrite: 就不能用 ‘/zy-server’ 作为代理字段,因为后端接口是带有的,
* 前端接口得加上自定义 ‘/mg’ 进行实现更多的代理控制行为:
* *接口例子:/mg/zy-server/sms/captcha
*
* proxy: {
'/mg': {
target: 'http://localhost:5220', //测试环境
pathRewrite: {
'^/mg': ''
}
},
},
*
* 比如: http://localhost:8081/mg/zy-server/sms/captcha 会被转发到
http://localhost:5220/zy-server/sms/captcha
* */