vue-cli代理服务器配置详解
在vue.config.js中写如下配置
module.exports = {
devServer: {
proxy: {
'/api': { // 匹配以/api为前缀请求地址,例如项目中的请求地址为http://location:8080/api+参数
target: '<url>', // 需要请求服务器地址
pathRewrite: {'^/api',''}, // 将请求地址中api替换为空字符串
ws: true, // 用于支付websocket
changeOrigin: true //用于控制请求头中的host值,为true时就是请求服务器端口号,为false时就是为代理服务器端口
},
'/foo': {
target: '<other_url>'
}
}
}
}