Skip to content
On this page

跨域解决方案之proxyTable

🕒 Published at: 5 years ago

在开发阶段,前端调用后端接口可能会出现跨域问题,在 vue-cli 中已经为我们集成了http-proxy-middleware,我们只需要在config/index.js中的 proxyTable 配置即可。

如果接口是www.aaa.com/get/getList,那么有两种配置方案:

  • 方法一
js
proxyTable: {
  '/api': {
    target: 'www.aaa.com',
    pathRewrite: {
      '^/api': '/get'
    }
  }
}

这个时候我们请求/api/getList就是请求www.aaa.com/get/getList

  • 方法二
js
proxyTable: {
  '/api': {
    target: 'www.aaa.com',
    pathRewrite: {
      '^/api': ''
    }
  }
}

这个时候我们请求/api/get/getList就是请求www.aaa.com/get/getList

个人博客:Uncle Wei

Last updated: