Skip to content

Commit

Permalink
docs: add cancel request (#12807)
Browse files Browse the repository at this point in the history
  • Loading branch information
hualigushi authored Nov 27, 2024
1 parent 1a7827a commit dca672c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/docs/docs/max/request.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,37 @@ export const request:RequestConfig = {};
```
Note that you should add type when importing
## Cancel request
Cancel the request using the fetch API method -- `AbortController`.
```tsx
import { request } from '@umijs/max';
import { Button } from 'antd';

const controller = new AbortController();

const HomePage: React.FC = () => {
const fetchData = async () => {
const res = await request('/api/getData', {
method: 'GET',
signal: controller.signal
})
}

const cancelData = () => {
controller.abort();
}
return (
<>
<Button onClick={fetchData}>send request</Button>
<Button onClick={cancelData}>cancel request</Button>
</>
);
};

export default HomePage;
```
## umi@3 to umi@4
In the upgrade from `umi@3` to `umi@4`, we discontinued umi-request and chose axios as the default request solution. Some functionality changes occurred in this switch.
Expand Down
31 changes: 31 additions & 0 deletions docs/docs/docs/max/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,37 @@ export const request:RequestConfig = {};
```
注意,在导入时要加 type
## 取消请求
使用 fetch API 方式 -- `AbortController` 取消请求。
```tsx
import { request } from '@umijs/max';
import { Button } from 'antd';

const controller = new AbortController();

const HomePage: React.FC = () => {
const fetchData = async () => {
const res = await request('/api/getData', {
method: 'GET',
signal: controller.signal
})
}

const cancelData = () => {
controller.abort();
}
return (
<>
<Button onClick={fetchData}>send request</Button>
<Button onClick={cancelData}>cancel request</Button>
</>
);
};

export default HomePage;
```
## umi@3 到 umi@4
`umi@3``umi@4` 的升级中,我们弃用了 umi-request ,选用了 axios 作为默认的请求方案。在这个更换中,我们的功能也发生了一些变化。
Expand Down

0 comments on commit dca672c

Please sign in to comment.