0
点赞
收藏
分享

微信扫一扫

Axios异步请求传参方式

兵部尚输 2022-07-12 阅读 93


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 条评论