2023-04-16 21:18:04 +08:00
|
|
|
---
|
|
|
|
title: 参数系列化
|
|
|
|
---
|
|
|
|
|
|
|
|
# {{ $frontmatter.title }}
|
|
|
|
|
|
|
|
::: tip {{ $frontmatter.title }}
|
|
|
|
支持自定义参数系列化器。
|
|
|
|
:::
|
|
|
|
|
2023-04-17 21:31:03 +08:00
|
|
|
## 自定义参数系列化器
|
|
|
|
|
|
|
|
可以用自己的方式对参数进行系列化。
|
|
|
|
|
|
|
|
```ts
|
|
|
|
import axios from 'axios-miniprogram';
|
|
|
|
|
|
|
|
axios('https://api.com', {
|
|
|
|
params: {
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
paramsSerializer(params) {
|
|
|
|
return qs.stringify(params);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
// 请求成功后做些什么
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
// 请求失败后做些什么
|
|
|
|
});
|
|
|
|
```
|