proxyTable 解决开发环境跨域问题 【VUE】

项目后台何其多,不可能每个都让后台设置,所以呀,前端是要自力更生的。

前端需要通过配置proxyTable来解决跨域问题。首先要找到config->index.js
13行的位置就是proxyTable了

  • 代理一个接口
proxyTable: {
  '/api': {
    target: 'http://xxxxxx.com', // 接口的域名
    // secure: false,  // 如果是https接口,需要配置这个参数
    changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
    pathRewrite: {
      '^/api': ''
    }
  }
},

  • 代理多个接口
proxyTable: {
  '/api': {
    target: 'http://xxxxxx.com', // 接口的域名
    // secure: false,  // 如果是https接口,需要配置这个参数
    changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
    pathRewrite: {
      '^/api': ''
    }
  },
  '/apis': {
    target: 'http://xxxxxx.com', // 接口的域名
    // secure: false,  // 如果是https接口,需要配置这个参数
    changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
    pathRewrite: {
      '^/apis': ''
    }
  }
}

猜你喜欢

转载自blog.csdn.net/github_39406334/article/details/88643130