// 使用默认进行请求(默认是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);
})
还没有评论,来说两句吧...