Axios异步请求传参方式

阅读 95

2022-07-12


1. get 请求

let data ={
"a": "1",
"b": "2"
}
this.$axios({
method: 'get',
url: 'xxxxx',
params: data,
headers: {
"Content-Type": "application/json",
"Authorization", "XXXXX"
}
}).then(res =>{
console.log("success")
}).catch(err =>{
console.log("error")
})

2. post 请求

let data ={
"a": "1",
"b": "2"
}
this.$axios({
method: 'post',
url: 'xxxxx',
data: data,
headers: {
"Content-Type": "application/json",
"Authorization", "XXXXX"
}
}).then(res =>{
console.log("success")
}).catch(err =>{
console.log("error")
})

3. put 请求

let data ={
"a": "1",
"b": "2"
}
this.$axios({
method: 'put',
url: 'xxxxx',
data: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
"Authorization", "XXXXX"
}
}).then(res =>{
console.log("success")
}).catch(err =>{
console.log("error")
})

4. delete请求

let data ={
"a": "1",
"b": "2"
}
this.$axios({
method: 'delete',
url: 'xxxxx',
data: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
"Authorization", "XXXXX"
}
}).then(res =>{
console.log("success")
}).catch(err =>{
console.log("error")
})


精彩评论(0)

0 0 举报