Vue-cli3配置代理转发devServer.proxy

版本不同可能配置的参数也不同vue

$ npx vue -V
@vue/cli 4.2.3

修改 配置文件 vue.config.jsapi

devServer: {
    port: port,
    open: true,
   
    proxy: {
      "/api": {
        target: "https://www.baidu.cn", //跨域网址
        secure: true, // 若是是https接口,须要配置这个参数
        changeOrigin: true, //自动修改http header里面的host
        pathRewrite: {
          "^/api": "", //路径的替换规则
        }
      }
    }
  }