`// 使用默認進行請求(默認是get)
axios({
url: "http://localhost:9999/student/student/getAllStudent"
}).then(res => {
console.log(res);
})
// 指定請求方式為get無參請求
axios({
url: "http://localhost:9999/student/student/getAllStudent",
method: "get"
}).then(res => {
console.log(res);
})
// 指定請求方式為get有參請求(方式一: 參數直接拼接到url)
axios({
url: "http://localhost:9999/student/student/getAllStudent?id=1",
method: "get",
}).then(res => {
console.log(res);
})
// 指定請求方式為get有參請求(方式二:參數放到params)
axios({
url: "http://localhost:9999/student/student/getAllStudent",
method: "get",
params: {
id: 1
}
}).then(res => {
console.log(res);
})
// axios post請求, 攜帶參數時content-type默認是application-json;
// 指定請求方式為post的無參請求
axios({
url: "http://localhost:9999/student/student/getAllStudent",
method: "post"
}).then(res => {
console.log(res);
})
// 指定請求方式為post的有參請求,使用params傳遞參數
axios({
url: "http://localhost:9999/student/student/getAllStudent",
method: "post",
params: {
id: 1,
name: '張三'
}
}).then(res => {
console.log(res);
})
// 指定請求方式為post的有參請求,使用data傳遞參數;
axios({
url: "http://localhost:9999/student/student/getAllStudent",
method: "post",
data: {
id: 1,
name: '張三'
}
}).then(res => {
console.log(res);
})
————————————————
版權聲明:本文為CSDN博主「尹東」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/yinge0508/article/details/113741370`