AXIOS请求方法

Axios是一个基于Promise的HTTP客户端,用于浏览器和Node.js。它提供了一组简洁且易于使用的API,用于发送HTTP请求。下面是Axios的所有请求方法及其示例:

get请求:

获取数据

axios.get('/api/users')
  .then(function (response) {
    console.log(response.data);
  })
  .catch(function (error) {
    console.log(error);
  });

post请求:

提交数据(表单提交+文件上传)

axios.put('/api/users/1', {
    name: 'John Doe',
    age: 26
  })
  .then(function (response) {
    console.log(response.data);
  })
  .catch(function (error) {
    console.log(error);
  });

put请求:

更新数据(将所有数据均推放到服务端)

axios.post('/api/users', {
    name: 'John Doe',
    age: 25
  })
  .then(function (response) {
    console.log(response.data);
  })
  .catch(function (error) {
    console.log(error);
  });

patch请求:

部分更新资源

PATCH /api/users/123 HTTP/1.1
Host: example.com
Content-Type: application/json

{
  "name": "John Doe",
  "age": 30
}

delete请求:

删除数据

axios.delete('/api/users/1')
  .then(function (response) {
    console.log(response.data);
  })
  .catch(function (error) {
    console.log(error);
  });

head请求:

获取资源的头部信息

axios.head('/api/users')
  .then(function (response) {
    console.log(response.headers);
  })
  .catch(function (error) {
    console.log(error);
  });

options请求:

用于获取服务器支持的HTTP方法。

axios.options('/api/users')
  .then(function (response) {
    console.log(response.data);
  })
  .catch(function (error) {
    console.log(error);
  });

  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值