axios-miniprogram/docs/pages/method/PUT.md

81 lines
1.4 KiB
Markdown
Raw Normal View History

2023-04-14 16:38:25 +08:00
---
title: PUT 请求
---
# {{ $frontmatter.title }}
::: tip {{ $frontmatter.title }}
HTTP PUT 请求方法使用请求中的数据创建或者替换目标资源。
:::
## 普通的 `PUT` 请求
2023-04-15 16:21:54 +08:00
可以传递第一个参数 `url` 发送 `PUT` 请求。
2023-04-14 16:38:25 +08:00
```ts
import axios from 'axios-miniprogram';
axios
.put('https://api.com/test')
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```
## 携带数据的 `PUT` 请求
2023-04-15 16:21:54 +08:00
也可以额外传递第二个参数 `data` 发送携带数据的 `PUT` 请求。
2023-04-14 16:38:25 +08:00
```ts
import axios from 'axios-miniprogram';
axios
.put('https://api.com/test/:id', {
id: 1,
name: 'test',
password: '123456',
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```
2023-04-15 16:21:54 +08:00
## 携带请求配置的 `PUT` 请求
2023-04-14 16:38:25 +08:00
2023-04-15 16:21:54 +08:00
也可以额外传递第三个参数 `config` 发送携带请求配置的 `PUT` 请求。
2023-04-14 16:38:25 +08:00
```ts
import axios from 'axios-miniprogram';
axios
.put(
2023-04-14 18:16:39 +08:00
'https://api.com/test/:id',
2023-04-14 16:38:25 +08:00
{
id: 1,
name: 'test',
password: '123456',
},
{
headers: {
'Content-Type': 'application/json',
},
},
)
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```
## 兼容性
2023-04-16 00:01:40 +08:00
<VPCompatibility wx my swan tt='1.0.0' qq tt2 qh />