方法一
在vue.config.js中添加如下配置:
devServer:{
proxy:"http://localhost:5000"
}
缺点:不能配置多个代理,如果请求了前端存在的资源,就会优先匹配,只有前端资源不存在时才会转发给服务器
方法二:
module.exports = {
devServer: {
proxy: {
'/test': {
target: 'http://localhost:8000',
pathRewrite:{'^/test'},
ws: true,
changeOrigin: true
},
'/demo': {
target: 'http://localhost:5000',
pathRewrite:{'^/demo':''},
ws: true,
changeOrigin: true
},
//'/foo': {
// target: '<other_url>'
//}
}
}
}
视频地址: