javascript - vue-cli做项目,跨域问题

查看:125
本文介绍了javascript - vue-cli做项目,跨域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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

解决方案

看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)
})

这篇关于javascript - vue-cli做项目,跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆