npm install --save-dev http-proxy-middleware
var proxy = require('http-proxy-middleware');
...............
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true,
proxy: {
'/api': {//匹配根路径
target: 'https://******/',//跨域要访问的地址及端口
changeOrigin: true,
}
},
}
- 用到的时候
axios.get('/api/v1/dairy/list')
.then(res => {
// 成功回调
console.log(res);
}, res => {
// 错误回调
console.log(res);
})