Axios发送请求时params和data的区别
在使用axios时,配置选项中包含params和data两者
区别:
因为params是添加到url的请求字符串中的,用于get请求。
而data是添加到请求体(body)中的, 用于post请求。
eg:post方法
this.axios({
method: 'post',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
url: 'xxxxxxxxxxxxxxxx',
data: JSON.stringify({
id: ids
})
}).then((res) => {
console.log(res);
this.$message.success('删除成功');
});
eg:get方法
this.axios.get('xxxxxxxxxx',{
params:{
username:aaa,
pwd:bbb,
}
}).then(function(res){
console.log(res)
if (res.data=="登录成功") {
alert("登录成功")
}
})