`// 使用默认进行请求(默认是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`