关于反向代理(跨域请求),简单说,访问一个地址 http://www.a.com 传送至 http://www.b.com。常见的就是nigix去做了。但今天我想说说VUE的反向代理的玩法。
重点:只有在开发VUE项目时,你才可以用到反向代理(跨域请求)。什么意思?
在 config/index.js中,找到dev中的proxyTable,此项就是设置你的跨域的设置,也就是你要代理的设置。但它只在dev中设置,也就是说,只有开发时,前端可以用此方法做跨域。
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/base': {
// target:'http://192.168.1.85:9520/base/',
target:'http://192.168.1.220:9528/base/',
// target:'http://192.168.1.84:9528/base/',
changeOrigin: true,
pathRewrite: {
'^/base': ''
}
}
},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 9529, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: false,
而生产环境,请联系你的运维人员,让他们帮忙做下nigix设置及其它服务器中的设置,即可。
具体说明,如下:
https://segmentfault.com/a/1190000014396546?utm_source=tag-newest