解決跨域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… 版權聲明:本文爲博主原創文章,轉載請附上博文連接!

相關文章
相關標籤/搜索