在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ axios跨域問題

axios跨域問題

1.我在main.js中設(shè)置了

axios.defaults.withCredentials=true
axios.defaults.crossDomain=true
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

在其他組件用的時(shí)候一旦帶參數(shù)例如:

self.axios.post('http://pj.dianmila.com/supersolid/supersolid_api.php?a=list',{offset:self.swiperlen},{headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).then(function(res) {
                        var datajson = res.data;
..................
                            }
                        } 
                    }).catch(function (error) {
                    alert('未能與服務(wù)器連接,請(qǐng)稍后嘗試')
                console.log(error);
            });

不加后面的headers的設(shè)置就不能跨域了為什么求教

2.當(dāng)我設(shè)置了headers之后傳過去的參數(shù)是{'offset':5}這種形式,我想要像ajax那樣直接offset:5,不包含在對(duì)象里面,如何實(shí)現(xiàn),要加什么配置選項(xiàng)

題目描述

題目來源及自己的思路

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

回答
編輯回答
愛是癌
axios.post('http://pj.dianmila.com/supersolid/supersolid_api.php?a=list',{offset:1},{
  headers: {'Content-Type':'application/x-www-form-urlencoded'},
  transformRequest: [function (data) {
    return Qs.stringify(data)
  }],
}).then(function(res) {
    console.log(res)
}).catch(function (error) {
    console.log(error);
})

transformRequest: [function (data) {
    return Qs.stringify(data)
  }],
2017年11月21日 08:49