Skip to content

Commit

Permalink
docs: add docs for customFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
BuptStEve committed Jul 21, 2020
1 parent 0b6106b commit c8a25ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions docs/config/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ export default {
}
```

## customFetch 自定义请求函数 <badge text="1.6.0+" />
适用于内置库覆盖不到的场景下使用,这是一个函数,将会接收接口相关配置,在函数内发起请求,返回值为一个 Promise。

```js
export default {
customFetch: ({ url, data, method }) => {
// ...
},
}
```

::: warning
从优先级上来说这个参数和 `reqType` 互相替代,例如:
1. 低优先级的 `reqType` 会被高优先级的 `customFetch` 覆盖(反之亦然)
2. 若是 `reqType``customFetch` 在同级同时配置时,控制台发出告警,并且实际以 `customFetch` 为准。
:::

## commonParams 公共参数
有时对于所有接口都需要添加一个公共参数。

Expand Down
6 changes: 5 additions & 1 deletion docs/config/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import TuaApi from 'tua-api'

new TuaApi({
host,
baseUrl, // 即原 host
reqType,
middleware,
customFetch,
axiosOptions,
jsonpOptions,
defaultErrorData,
Expand All @@ -26,6 +27,9 @@ new TuaApi({
## middleware 中间件函数数组
【所有】请求都会调用的中间件函数数组!适合添加一些通用逻辑,例如接口上报。

## customFetch 自定义请求函数 <badge text="1.6.0+" />
这是一个函数,将会接收接口相关配置,在函数内发起请求,返回值为一个 Promise。

## axiosOptions 透传 axios 配置参数
【通用】的配置,会和之后的配置合并。

Expand Down

0 comments on commit c8a25ce

Please sign in to comment.