VUE.JS部署axios请求到Tomcat出现跨域问题

新手上路,请多包涵

问题描述

我需要在VUE调用供应商提供的外部WADL(应该是用的JEREY框架,POST)地址,在本地通过config/index.js下proxyTable配置可以运行并调用接口成功。

现在需要部署到服务器的tomcat上,但一直报 XMLHttpRequest cannot load http://:7001/getuser. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://:8009' is therefore not allowed access. 在网上的帖子都通不过(web.xml过滤器配置、JSONP、QS)。

现在我只能修改tomcat的配置已经http header,接口与后端不做修改,请问能怎么做的到。请大家指教一下

问题出现的环境背景及自己尝试过哪些方法

clipboard.png

clipboard.png

clipboard.png

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
axios.post(process.env.API_HOST + '/*ser', {//

      TYPE: 'V',
      USER_NAME: this.username
    }).then(function (response, headers) {
        if (response.status === 200) {
          if (response.data.l_RET_STATUS == 'Y') {
            window.sessionStorage.userName = self.username;
            this.showupError = false;
            this.$router.push('/home');
          } else {
            this.showupError = true;
          }
        } else {
          alert('网络错误,请稍后再试!')
        }
      }
    ).catch(function (error) {
      alert('请求错误')
    });

你期待的结果是什么?实际看到的错误信息又是什么?

阅读 6.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题