axios请求方式


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM