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);
    })
posted @   我也有梦想呀  阅读(780)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示