// vue.config.js
let proxyObj = {}
proxyObj['/'] = {
ws: false, // websocket
target: "http://localhost:8081",
changeOrigin: true,
pathRewrite: {
'^/': '/'
}
}
module.exports = {
devServer:{
host: 'localhost',
port: 8080, // 前端端口
proxy: proxyObj
}
}
假设请求后端 http://localhost:5000/api/home
// vue.config.js
module.exports = {
devServer:{
proxy:{
'/api':{
target: 'http://localhost:5000',
changeOrigin: true
}
}
}
}
// 发请求
axios.get('/api/home')
// 有时要加上后端要求的额外的 headers