vue-cli做项目,跨域问题

vue-cli做项目,开发环境跨域,访问测试环境也跨域,项目提交到测试服务器,不跨域,
通过vue-resource处理,对于这种可能跨域,也可能不跨域的问题
请问如何配置?

阅读 3.6k
2 个回答

开发时用Proxytable代理;上线可以用nginx反向代理的方式解决

看build文件下的dev-server,找到这行var proxyTable = config.dev.proxyTable,然后配置这个proxyTable

'/baidu': {
    target: 'https://xx.xx.com',
    changeOrigin: true,
    pathRewrite: {
      '^/baidu': ''
    }
  }

使用的时候

Vue.http.options.crossOrigin = true
Vue.http.post('/baidu/xx/xx', {       
  'data': data
}).then(response => {
  console.log(response)
}, response => {
  this.personSearch(img)
  console.log(response)
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
1 篇内容引用
推荐问题