axios的传参方式

在使用 Axios 发送 HTTP 请求时,有三种常见的传参方式:dataparams 和路径参数

1、data传参

  this.$axios({
     method: "post",
     url: "http://localhost:8080/api/user/login",
     data: {
             userId: this.userId,
             password: this.password,
          },
   })
    .then((res) => {
      console.log(res);
  })
  .catch(error => {
    console.error(error);
  });

2、使用 params 传递查询参数:

axios.get('/api/users', {
  params: {
    page: 1,
    limit: 10
  }
})
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

params参数通常用于GET请求中添加查询参数,而对于POST请求,一般使用data参数来传递请求体数据。

3、使用路径参数传递数据:

 deleteUser(userId) {
      this.$axios({
        method: 'post',
        url: 'http://localhost:8080/api/user/deleteUser/' + userId,
      }).then((res) => {
        //显示删除成功
        this.$message({
          message: res.data.message,
          type: "success",
        });
        //刷新表格数据
        this.userAll();
      });

相关推荐

  1. axios方式

    2024-01-18 21:10:02       56 阅读
  2. springboot+axios问题

    2024-01-18 21:10:02       33 阅读
  3. C# 方法

    2024-01-18 21:10:02       37 阅读
  4. js跳转方式

    2024-01-18 21:10:02       31 阅读
  5. uniapp页面间方法

    2024-01-18 21:10:02       39 阅读
  6. uniapp 跨页面几种方式

    2024-01-18 21:10:02       53 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-18 21:10:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-18 21:10:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-18 21:10:02       82 阅读
  4. Python语言-面向对象

    2024-01-18 21:10:02       91 阅读

热门阅读

  1. 力扣39. 组合总和

    2024-01-18 21:10:02       55 阅读
  2. 关于OC中变量相关知识点

    2024-01-18 21:10:02       54 阅读
  3. MySQL中WITH AS语句的使用

    2024-01-18 21:10:02       60 阅读
  4. iOS长按时无法保存图片问题解决方案

    2024-01-18 21:10:02       83 阅读