在vue.cofing.js中配置代理规则:
module.exports = {
// 开启代理服务器 (方式一)
// devServer: {
// proxy: 'http'
// },
// 开启代理服务器 (方式二)
devServer: {
proxy: {
'^/api': { // 匹配所有api开头的请求路径
target: 'http:localhost:8081', //代理目标的基础路径
pathRewrite:{'^/api':''} // API路径改写为空
// ws: true,
// changeOrigin: true
},
'^/api1': { // 匹配所有api1开头的请求路径
target: 'http:localhost:8082', //代理目标的基础路径
pathRewrite:{'^/api1':''}
// ws: true,
// changeOrigin: true
}
}
}
}