diff --git a/docs/docs/docs/max/request.en-US.md b/docs/docs/docs/max/request.en-US.md index 1312e80d4481..464f0095c1a5 100644 --- a/docs/docs/docs/max/request.en-US.md +++ b/docs/docs/docs/max/request.en-US.md @@ -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 ( + <> + + + + ); +}; + +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. diff --git a/docs/docs/docs/max/request.md b/docs/docs/docs/max/request.md index 06a9b62039de..e0abe0b70509 100644 --- a/docs/docs/docs/max/request.md +++ b/docs/docs/docs/max/request.md @@ -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 ( + <> + + + + ); +}; + +export default HomePage; +``` + ## umi@3 到 umi@4 在 `umi@3` 到 `umi@4` 的升级中,我们弃用了 umi-request ,选用了 axios 作为默认的请求方案。在这个更换中,我们的功能也发生了一些变化。