// vue.config.js 文件中
module.exports={
devServer:{
proxy:{
'/lujing':{
target:'http://localhost:5000',
pathRewrite:{'^/lujing':''},
// ws:true, //用于支持websocket
// changeOrigin:true //用于控制请求头中的host值
},
'/lujing2':{
target:'http://localhost:5001',
pathRewrite:{'^/lujing2':''},
// ws:true, //用于支持websocket
// changeOrigin:true //用于控制请求头中的host值
}
},
}
}
vue-cli 开启代理服务器(解决跨域请求问题)
于 2021-08-09 16:57:58 首次发布
在Vue项目的vue.config.js配置文件中,通过devServer的proxy选项可以设置代理,解决开发环境中API请求跨域的问题。示例配置了两个代理,分别对应'http://localhost:5000'和'http://localhost:5001'的接口,通过pathRewrite将'/lujing'和'/lujing2'路径重写,确保请求正确发送。
摘要由CSDN通过智能技术生成