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

鍍金池/ 問(wèn)答/HTML5  HTML/ axios跨域

axios跨域

我在main.js中已經(jīng)設(shè)置了

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

然后我在一個(gè)組件中用到了axios,項(xiàng)目上需要攜帶cookie過(guò)去,大致函數(shù)如下

this.$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;
                        if(datajson.state == 1) {
                            for(let i in datajson.list) {
                                self.swiper.off('reachEnd')
                                self.swiperlist.push(datajson.list[i])
                                self.swiperlen++;
                            }
                        } 
                    }).catch(function (error) {
                    alert('未能與服務(wù)器連接,請(qǐng)稍后嘗試')
                console.log(error);

然后在不傳參數(shù)的情況下是可以不寫(xiě)后面的headers設(shè)置的,但是一旦我?guī)Я藚?shù)進(jìn)去,全局設(shè)置的headers就無(wú)效了,一定要加上后面的headers才能傳過(guò)去,而且即使傳過(guò)去了,調(diào)試?yán)锩婵吹绞莧offset:5}:
會(huì)無(wú)緣無(wú)故多了個(gè):服務(wù)器識(shí)別不了,求大神解答

問(wèn)題描述

問(wèn)題出現(xiàn)的環(huán)境背景及自己嘗試過(guò)哪些方法

相關(guān)代碼

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

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

題目描述

題目來(lái)源及自己的思路

相關(guān)代碼

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

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

回答
編輯回答
伴謊

正常對(duì)應(yīng)的是content-type: application/json;charset=UTF-8
解決方案就是加上transformRequest自己處理一下數(shù)據(jù),我選擇使用qs處理,地址。

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);
  })





clipboard.png

2018年6月18日 18:12