Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

vue 请求跨域问题解决方法?

今天练习vue时,写了一个登录页面和注册页面,

在进行数据注册的时候,在请求服务器时报跨域问题。

1594979814(1).jpg

之后在网上查vue 跨域问题。

大部分都是说 在Config/index.js 里面进行配置proxyTable: {}

初始的proxyTable: {}是个空的,

改成

proxyTable: {
     '/api': {  //使用"/api"来代替"http://f.apiplus.c"
       target: 'https://shwy.xxx.xxx/', //请求服务器地址
       changeOrigin: true, //是否是跨域
       pathRewrite: {
         '^/api': '' //路径重写
         }
     }
   },

但是改过之后,还是会报错,不过不是报跨域问题了。

1594980327(1).jpg

变成http://localhost:8080/addUser 请求了,此处表示很懵。

如果不按照config/index.js的配置请求的话,按照这种的

# this.$global.serverPath 是我的后台请求路径 #
var url = this.$global.serverPath + "/addUser?username="+this.username+"&password="
        //   +this.password+"&wqpassword="+this.eqpassword+"&phone="+this.phone;
        //   this.$axios({
        //       method:'post',
        //       url:url,
        //       headers:{
        //           'Context-Type':'application/json',
        //           'Authorization':'Bearer'+localStorage.getItem("token"),
        //       'Access-Control-Allow-Origin': '*',
        //       },
        //   }).then(res=>{
        //       if(res.data != null){
        //           this.$message.success("注册成功,请记好您的账号和密码");
        //           return;
        //       }else{
        //           this.$message.error("服务器繁忙,请稍后再试");
        //           return;
        //       }
        //   })
        // }else{
        //   this.$message.warning("请填写正确");
        //   return;
        // }

会报

1594979814(1).jpg

跨域错误

在线求解,急!!!
求各位给看看。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

状态码是 404 说明没有这个接口。你试试路径改为 /api/addUser


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...