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("登入成功")
}
})