Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add cancel request #12807

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading