Skip to content

Commit ba94bd9

Browse files
committed
Merge branch 'feature/[email protected]'
2 parents d777a95 + 48ad236 commit ba94bd9

File tree

8 files changed

+106
-12
lines changed

8 files changed

+106
-12
lines changed

docs/api/01-alova.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,53 @@ const getUsers = alovaInstance.Get('/users', {
159159
});
160160
```
161161

162+
## `[3.3.0+]`alova.Request()
163+
164+
Create a method instance.
165+
166+
- **Type**
167+
168+
```ts
169+
interface Alova {
170+
Request(config?: AlovaMethodCreateConfig): Method;
171+
}
172+
```
173+
174+
- **Parameter**
175+
176+
| Parameter name | Type | Description |
177+
| -------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
178+
| url | string | request url |
179+
| method | string | request method, such as GET/POST, default is `GET` |
180+
| headers | object | request header, [view details](/tutorial/getting-started/basic/method) |
181+
| params | object | request parameters, [view details](/tutorial/getting-started/basic/method) |
182+
| name | string | method object name, in [updateState](/tutorial/client/in-depth/update-across-components), [invalidateCache](/tutorial/cache/manually-invalidate), [setCache](/tutorial/cache/set-and-query), and [fetch function](/tutorial/client/strategy/use-fetcher) can get the corresponding method instance by name or wildcard |
183+
| timeout | number | request timeout, [see details](/tutorial/getting-started/basic/method) |
184+
| cacheFor | cacheForConfig | response cache time, [see details](/tutorial/cache/mode) |
185+
| hitSource | string | hit source method instance, when the source method instance request is successful, the cache of the current method instance will be invalidated, [see details](/tutorial/cache/auto-invalidate) |
186+
| transform | function | Convert response data, [View details](/tutorial/getting-started/basic/method) |
187+
| shareRequest | boolean | Request-level shared request switch, [View details](/tutorial/getting-started/basic/method) |
188+
| meta | any | method metadata, [View details](/tutorial/getting-started/basic/method-metadata) |
189+
190+
> In addition to the configurable parameters above, other parameters supported by the request adapter are also supported.
191+
192+
- **Return**
193+
194+
method instance
195+
196+
- **Example**
197+
198+
```ts
199+
const getUsers = alovaInstance.Request({
200+
url: '/users',
201+
method: 'GET',
202+
params: {
203+
id: 1
204+
}
205+
// ...
206+
});
207+
```
208+
162209
## alova.Get()
163210

164211
Create a method instance for a GET request.

docs/tutorial/02-getting-started/03-basic/03-method.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ Parameter description:
5656
- `data` is the request body data;
5757
- `config` is the request configuration object, which includes the request header, params parameters, request behavior parameters and other configurations;
5858

59-
You can also create your own custom method instance, which is useful when dynamically specifying the request type.
59+
You can also create your own custom method instance by `alova.Request`, which is useful when dynamically specifying the request type.
6060

6161
```javascript
62-
import { Method } from 'alova';
63-
64-
const method = new Method('GET', alovaInstance, '/api/users', {
62+
const method = alovaInstance.Request({
63+
url: '/api/users',
64+
method: 'GET', // default is GET
6565
params: {
6666
ID: 1
6767
}

docs/tutorial/07-project/01-best-practice/01-manage-apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ In the **user component**, the method function can be directly imported for use,
133133
</template>
134134
<script setup>
135135
import { getUserInfo, editUserInfo } from '@/api/methods/user';
136-
import { useRequest, invalidateCache } from 'alova';
136+
import { useRequest, invalidateCache } from 'alova/client';
137137
138138
const userId = 1; // use 1 as userId
139139
const { loading, error, data } = useRequest(getUserInfo(userId));

i18n/zh-CN/docusaurus-plugin-content-docs/current/api/01-alova.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,53 @@ class MethodSnapshotContainer<AG extends AlovaGenerics> {
130130
}
131131
```
132132

133+
## alova.Request()
134+
135+
创建 method 实例。
136+
137+
- **类型**
138+
139+
```ts
140+
interface Alova {
141+
Request(config?: AlovaMethodCreateConfig): Method;
142+
}
143+
```
144+
145+
- **参数**
146+
147+
| 参数名 | 类型 | 说明 |
148+
| ------------ | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
149+
| url | string | 请求地址,相对于 baseURL |
150+
| method | string | 请求方法,默认为 GET |
151+
| headers | object | 请求头,[查看详情](/tutorial/getting-started/basic/method) |
152+
| params | object | 请求参数,[查看详情](/tutorial/getting-started/basic/method) |
153+
| name | string | method 对象名称,在 [updateState](/tutorial/client/in-depth/update-across-components)[invalidateCache](/tutorial/cache/manually-invalidate)[setCache](/tutorial/cache/set-and-query)、以及 [fetch 函数](/tutorial/client/strategy/use-fetcher)中可以通过名称或通配符获取对应 method 实例 |
154+
| timeout | number | 请求超时时间,[查看详情](/tutorial/getting-started/basic/method) |
155+
| cacheFor | cacheForConfig | 响应缓存时间,[查看详情](/tutorial/cache/mode) |
156+
| hitSource | string | 打击源方法实例,当源方法实例请求成功时,当前方法实例的缓存将被失效,[查看详情](/tutorial/cache/auto-invalidate) |
157+
| transform | function | 转换响应数据,[查看详情](/tutorial/getting-started/basic/method) |
158+
| shareRequest | boolean | 请求级共享请求开关,[查看详情](/tutorial/getting-started/basic/method) |
159+
| meta | any | method 元数据, [查看详情](/tutorial/getting-started/basic/method-metadata) |
160+
161+
> 除了可配置上面的参数外,还支持请求适配器支持的其他参数。
162+
163+
- **返回**
164+
165+
method 实例
166+
167+
- **示例**
168+
169+
```ts
170+
const getUsers = alovaInstance.Request({
171+
url: '/users',
172+
method: 'GET',
173+
params: {
174+
id: 1
175+
}
176+
// ...
177+
});
178+
```
179+
133180
## alova.Get()
134181

135182
创建 GET 请求的 method 实例。

i18n/zh-CN/docusaurus-plugin-content-docs/current/tutorial/02-getting-started/03-basic/03-method.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ alova 共提供了 GET、POST、PUT、DELETE、HEAD、OPTIONS、PATCH 7 种请
5656
- `data`为请求体数据;
5757
- `config`为请求配置对象,其中包含了请求头、params 参数等、请求行为参数等配置;
5858

59-
你也可以自定义创建 method 实例,这在动态指定请求类型时很有用。
59+
你也可以通过`alova.Request`自定义创建 method 实例,这在动态指定请求类型时很有用。
6060

6161
```javascript
62-
import { Method } from 'alova';
63-
64-
const method = new Method('GET', alovaInstance, '/api/users', {
62+
const method = alovaInstance.Request({
63+
url: '/api/users',
64+
method: 'GET', // 默认为GET
6565
params: {
6666
ID: 1
6767
}

i18n/zh-CN/docusaurus-plugin-content-docs/current/tutorial/07-project/01-best-practice/01-manage-apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const removeUser = id => userAlova.Delete('/user/' + id);
133133
</template>
134134
<script setup>
135135
import { getUserInfo, editUserInfo } from '@/api/methods/user';
136-
import { useRequest, invalidateCache } from 'alova';
136+
import { useRequest, invalidateCache } from 'alova/client';
137137
138138
const userId = 1; // 使用1作为userId
139139
const { loading, error, data } = useRequest(getUserInfo(userId));

i18n/zh-CN/docusaurus-plugin-content-docs/version-v2/tutorial/07-best-practice/01-manage-apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const removeUser = id => userAlova.Delete('/user/' + id);
133133
</template>
134134
<script setup>
135135
import { getUserInfo, editUserInfo } from '@/api/methods/user';
136-
import { useRequest, invalidateCache } from 'alova';
136+
import { useRequest, invalidateCache } from 'alova/client';
137137
138138
const userId = 1; // 使用1作为userId
139139
const { loading, error, data } = useRequest(getUserInfo(userId));

versioned_docs/version-v2/tutorial/07-best-practice/01-manage-apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ In the **user component**, the method function can be directly imported for use,
133133
</template>
134134
<script setup>
135135
import { getUserInfo, editUserInfo } from '@/api/methods/user';
136-
import { useRequest, invalidateCache } from 'alova';
136+
import { useRequest, invalidateCache } from 'alova/client';
137137
138138
const userId = 1; // use 1 as userId
139139
const { loading, error, data } = useRequest(getUserInfo(userId));

0 commit comments

Comments
 (0)