提示:仅为个人理解
一 为什么用反向代理?
提示:解决跨域问题
如前端地址为 http://localhost:8080/#/ 后端是 http://10.10.10.10:8080 跟 http://10.11.11.11:8080 访问为跨域
二 解决代码
提示:更改 vue.config.js
module.exports = {
publicPath: './',
assetsDir: 'static',
devServer: {
proxy: {
'/aaa': { //代理接口
target: 'http://10.10.10.10:8080', // 后端接口
pathRewrite: { '^/aaa': '/aaa' }, //重定向
changeOrigin: true // 是否跨域
},
'/bbb': { // 账户管理
target: 'http://10.11.11.11:8080', // 后端接口
pathRewrite: { '^/bbb': '/' }, //重定向
changeOrigin: true // 是否跨域
},
}
},
}
反向代理原理有大白话可以理解为 微信聊天, 以前聊天都得面对面,但是呢A被隔离了没钱花,现在可以使用微信作为中间沟通桥梁 A(前台)
通过微信跟B(服务器)
说要钱 你给我微信转账.那B(服务器)
收到消息之后就通过微信转给A(前台)
而微信就作为中间的一个沟通桥梁来链接两边