解决跨域axios

在实际项目开发过程当中vue cli自带的服务器,可是咱们实际要去请求咱们的数据接口,服务器与服务器之间产生了一个代理跨域问题,咱们须要修改自带服务的配置。在config 中的index文件中,有一个proxyTable参数html

参数修改以下:vue

proxyTable: {   '/list': {     target: 'xxx.xxx.com/xxx/6',     pathRewrite: {       '^/list': '/'     }   } },api

若是须要跨域那么须要加上参数changeOrigin:true跨域

proxyTable: {   '/list': {     target: 'xxx.xxx.com/xxx/6',服务器

changeOrigin:true,     pathRewrite: {       '^/list': '/'     }   } },post

请求过程就须要这样写ui

//帐号登录提交this

submitForm:function (formName) {   var info={     user_phone: this.info.username,     user_pwd: this.info.password,     verify_code: this.info.password   }   var  that=this;     this.http.post('/list/login',info).then(function (res) {
        console.log(res.data)
          if(res.data.code==2000){
              this.router.push({ path: 'OrderTracking'}).net

}else (res.data.code==4000){                 alert("登录失败")           }    }) } 项目上线时后台配置 #商家管理员端 server {         listen       80; server_name  xxxx.xxxx.xxxx.com; #社区端 location /list/ { proxy_set_header X-Real-IP remote_addr;
            proxy_set_header X-Forwarded-Forproxy_add_x_forwarded_for;             proxy_set_header X-Nginx-Proxy true;             proxy_set_header Connection ""; proxy_pass api.xxxx.xxx.com/seller/; } location /ui/ { proxy_set_header X-Real-IP remote_addr;
            proxy_set_header X-Forwarded-Forproxy_add_x_forwarded_for;             proxy_set_header X-Nginx-Proxy true;             proxy_set_header Connection ""; proxy_pass api.xxxx.xxx.com/public/; } location / { root   /www/xxx/xxx; index  index.html index.htm; }     }3d


做者:幕僚珂 来源:CSDN 原文:blog.csdn.net/qq_33559304… 版权声明:本文为博主原创文章,转载请附上博文连接!

相关文章
相关标签/搜索