vue element admin 代理配置

 vue项目的话,在vue.config.js 里面找到devServer配置代理
 
  devServer: {
    port: 8081,  // 端口
    // open: true,  // 是否自动打开浏览器
    overlay: {
      warnings: false,
      errors: true
    },
    hot: true, //单纯设置为true的时候,如果编译报错,会抛出错误,你重新改成正确的,这个时候又会触发重新编译,整个浏览器会重新刷新!
    headers: {
      'Access-Control-Allow-Origin': '*',     //允许所有域名访问 
      'Access-Control-Allow-Credentials': 'true' //是否允许后续请求携带认证信息(cookies),该值只能是true,否则不返回
    },
    host: '0.0.0.0',
    proxy: {  // 代理
      '/admin': {
        target: 'http://192.168.1.100:8080', // 后台端口地址
        changeOrigin: true, // 将基于名称的虚拟托管网站的选项,如果不配置,请求会报404  如果接口跨域,需要进行这个参数配置
        ws: true, // true / false,是否代理websockets
        secure: false, // 如果是https接口,需要配置这个参数
        pathRewrite: {
          '^/admin': ''  //pathRewrite是使用proxy进行代理时,对请求路径进行重定向以匹配到正确的请求地址
        }
      }
    }
  }
原文地址:https://www.cnblogs.com/yangxuming/p/14255490.html