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);
      })原文:https://www.cnblogs.com/wulzt/p/10460810.html