1.我在main.js中设置了
axios.defaults.withCredentials=true
axios.defaults.crossDomain=true
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
在其他组件用的时候一旦带参数例如:
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('未能与服务器连接,请稍后尝试')
console.log(error);
});
不加后面的headers的设置就不能跨域了为什么求教
2.当我设置了headers之后传过去的参数是{'offset':5}这种形式,我想要像ajax那样直接offset:5,不包含在对象里面,如何实现,要加什么配置选项
题目描述
题目来源及自己的思路
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
这是后台的数据格式 post不有常用4种Content-Type头么
用form-data应该满足你的需求了 不过后台的支持这种格式