[vue]vue.config.js之proxy代理配置
配置代理:基础 devServer: { proxy: { // 配置多个代理(配置一个 proxy: 'http://localhost:4000' // 本地模拟数据服务器) &
·
配置代理:基础
devServer: {
proxy: {
// 配置多个代理(配置一个 proxy: 'http://localhost:4000' // 本地模拟数据服务器)
"^/v1": {
target: "https://monitor-api.xxx", //
ws: true,
changeOrigin: true,
},
"/d": {
target: "https://monitor-third-pard-api.xxx", //431
ws: true,
changeOrigin: true
},
"^/api": {
target: "https://monitor-third-pard-api.xxx", //431
ws: true,
changeOrigin: true
},
"/login": {
target: "https://monitor-third-pard-api.xxx", //431
ws: true,
changeOrigin: true
},
"/public": {
target: "https://monitor-third-pard-api.xxx", //431
ws: true,
changeOrigin: true
}
}
},
配置代理的时候可以通过以上方式,但是当多个路径使用同一个代理的时候,按上述方式就有点不简洁,网上搜了一遍都没有找到合适的说明,最后尝试了一下,发现以下方式可行
配置代理:优化
devServer: {
proxy: {
// 配置多个代理(配置一个 proxy: 'http://localhost:4000' // 本地模拟数据服务器)
"^/v1": {
target: "https://monitor-api.xxx", //
ws: true,
changeOrigin: true,
},
"^/(d|api|login|public)/" : {
target: ""https://monitor-third-pard-api.xxx", //431
ws: true,
changeOrigin: true
}
}
},
更多推荐
已为社区贡献4条内容
所有评论(0)