-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* type: format result type * type: sync * type: format result type * chore: upgrade v2 * feat: upgrade use-request plugin * docs: add use-request format result docs * docs: add migrate v2 * docs: opt * docs: demo * docs: add route * test: use-request plugin unit test
- Loading branch information
1 parent
6e59ff7
commit 2eb30fd
Showing
33 changed files
with
490 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 🫶 Migrate to v2 version | ||
|
||
:::info | ||
|
||
- useRequest plugin option | ||
|
||
::: | ||
|
||
## 1、useRequest plugin option | ||
|
||
In order to have good type hints and subsequent expansion in the v2 version of useRequest plug-in system, we have redesigned the usage of plugin option. You only need to make simple changes to achieve migration. | ||
|
||
## v1 use | ||
|
||
```typescript | ||
const { data } = useRequest( | ||
() => serviceFn(), | ||
{ | ||
...option, | ||
...pluginOption, | ||
}, | ||
[useFormatterPlugin, ...otherPlugins], | ||
) | ||
``` | ||
|
||
## v2 use | ||
|
||
```typescript | ||
const { data } = useRequest( | ||
() => serviceFn(), | ||
{ | ||
...option, | ||
pluginOptions: { | ||
...pluginOption, | ||
}, | ||
}, | ||
[useFormatterPlugin, ...otherPlugins], | ||
) | ||
``` | ||
|
||
Just migrate it to `pluginOptions` based on the original plugin option. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 🫶 迁移到 v2 版本 | ||
|
||
:::info | ||
|
||
- useRequest plugin option | ||
|
||
::: | ||
|
||
## 1、useRequest plugin option | ||
|
||
v2 版本的 useRequest 插件系统为了有良好的类型提示以及后续拓展,我们重新设计了 plugin option 的使用方式,你只需要进行简单的改变即可达到迁移。 | ||
|
||
## v1 use | ||
|
||
```typescript | ||
const { data } = useRequest( | ||
() => serviceFn(), | ||
{ | ||
...option, | ||
...pluginOption, | ||
}, | ||
[useFormatterPlugin, ...otherPlugins], | ||
) | ||
``` | ||
|
||
## v2 use | ||
|
||
```typescript | ||
const { data } = useRequest( | ||
() => serviceFn(), | ||
{ | ||
...option, | ||
pluginOptions: { | ||
...pluginOption, | ||
}, | ||
}, | ||
[useFormatterPlugin, ...otherPlugins], | ||
) | ||
``` | ||
|
||
只需要在原来的 plugin option 的基础上,将其迁移到 `pluginOptions` 下即可。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/hooks/src/useRequest/docs/formatResult/demo/demo.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<div>Origin name: {{ loading ? 'loading' : data }}</div> | ||
<div>Format: {{ loading1 ? 'loading' : JSON.stringify(formatData) }}</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { useRequest } from 'vue-hooks-plus' | ||
function getUsername(params: { desc: string }): Promise<string> { | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(`vue-hooks-plus ${params.desc}`) | ||
}, 1000) | ||
}) | ||
} | ||
const { data, loading } = useRequest(() => getUsername({ desc: 'good' })) | ||
const { data: formatData, loading: loading1 } = useRequest(() => getUsername({ desc: 'good' }), { | ||
formatResult(res) { | ||
return { | ||
name: `formatter ${res}`, | ||
age: 18, | ||
} | ||
}, | ||
}) | ||
</script> |
30 changes: 30 additions & 0 deletions
30
packages/hooks/src/useRequest/docs/formatResult/index.en-US.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
map: | ||
# 映射到docs的路径 | ||
path: /useRequest/formatResult/ | ||
source: | ||
show: false | ||
--- | ||
|
||
# Format the request result | ||
|
||
## v1 use | ||
|
||
Since v1 version `useRequest` needs to guarantee a good plug-in system, format is too invasive for the system, the formatting here is `useFormatResult`, format data to `useFormatResult` after the request data is completed, `useFormatResult` can well support `typescript` type prompt. <br /> | ||
|
||
<a href="/docs/hooks/en/useFormatResult/" >Jump to useFormatResult</a> | ||
|
||
## v2 use | ||
|
||
It now supports ts types very well. | ||
|
||
<demo src="./demo/demo.vue" | ||
language="vue" | ||
title="" | ||
desc="format the request result"> </demo> | ||
|
||
## Options | ||
|
||
| Property | Description | Type | Default | | ||
| ------------ | ------------------------- | --------------------------------- | ------- | | ||
| formatResult | format the request result | `(response: TData) => FormatData` | - | |
Oops, something went wrong.