
module.exports = {
//开启代理服务器
devServer: {
proxy: 'http://localhost:5000',
}
}

重启服务器,重启脚手架


我们请求一个http://localhost:9000/demo/user/list地址
getUserList() {
axios({
method: 'get',
url: 'http://localhost:8080/demo/user/list',
})
.then(res => {
console.log(res)
this.tableData = res.data
})
devServer: {
proxy: 'http://localhost:9000',
},
devServer: {
proxy: {
//请求前缀
'api': {
target: '',
ws: true, //用于支持websocket
changeOrigin: true, //用于控制请求头中的host值,默认是true
},
'/foo': {
target: '' ,
},
},
},
devServer: {
proxy: {
//请求前缀
'/atguigu': {
target: 'http://localhost:5000',
},
},
},

pathRewrite: { '^/atguigu': '' },
devServer: {
proxy: {
//请求前缀
'/atguigu': {
target: 'http://localhost:5000',
pathRewrite: { '^/atguigu': '' },
},
},
},
ws: true, //用于支持websocket
changeOrigin: true, //用于控制请求头中的host值,默认是true
devServer: {
proxy: {
//请求前缀
'/atguigu': {
target: 'http://localhost:5000',
pathRewrite: { '^/atguigu': '' },
ws: true, //用于支持websocket
changeOrigin: true, //用于控制请求头中的host值,默认是true
},
// '/foo': {
// target: '',
// },
'/demo': {
target: 'http://localhost:5001',
pathRewrite: { '^/demo': '' },
ws: true, //用于支持websocket
changeOrigin: true, //用于控制请求头中的host值,默认是true
},
},
},
getUserList() {
axios({
method: 'get',
url: '/abc/demo/user/list',
})
.then(res => {
console.log(res)
this.tableData = res.data
})
//开启代理服务器
devServer: {
proxy: {
'/abc': {
target: 'http://localhost:9000',
ws: true,
changeOrigin: true,
pathRewrite: {
'^/abc' : ''
}
}
}
},