All notable changes to this project will be documented in this file. See standard-version for commit guidelines.
2.0.4 (2023-10-16)
2.0.3 (2023-06-13)
- expose
definePlugin
(2a03d38)
2.0.2 (2023-06-02)
2.0.1 (2023-06-01)
-
Use
vue-demi
to be compatible with Vue 2 #38 -
Added custom cache
getCache
,setCache
, andclearCache
. -
When caching is enabled, requests with the same
cacheKey
will be cached and reused. -
Added
runAsync
andrefreshAsync
, which return aPromise
. -
Added
definePlugin
to extend the functionality of useRequest through plugins. -
In throttle/debounce mode,
runAsync
can be used to return a normalPromise
. -
Added
useRequestProvider
hooks to inject options configuration. -
Added
refreshDepsAction
option to customize the behavior afterrefreshDeps
is triggered. -
refreshDepsAction
will also be triggered by changes inrefreshDeps
whenmanual=true
. -
Added
loadingKeep
. -
Removed the integrated request library and
service
no longer supports strings or objects. Migration Guide -
Removed
formatResult
. Migration Guide -
Removed
queryKey
, i.e., parallel mode is removed Migration Guide -
run
no longer returns aPromise
Migration Guide -
When a request fails,
data
is no longer cleared #82 -
Modified the logic of
ready
Migration Guide -
ready
now supports passing a function that returns a Boolean value #166 -
data
anderror
changed toshallowRef
-
usePagination
removedreload
method andreloading
. If needed, they can be implemented separately. -
Removed
RequestConfig
component Migration Guide -
Refactored
useLoadMore
, see details for specific API API Description -
cacheKey
can now be passed a function:cacheKey: (params?: P) => string
useRequest(getUser, { cacheKey: (params?: P): string => { // When initialized, `params` will be undefined, so we need to manually check and return an empty string if (params) { return `user-key-${params[0].name}`; } return ''; }, });
-
Some
options
support reactivity, as shown below:type ReactivityOptions = { loadingDelay: number | Ref<number>; loadingKeep: number | Ref<number>; pollingInterval: number | Ref<number>; debounceInterval: number | Ref<number>; debounceOptions: DebounceOptions | Reactive<DebounceOptions>; throttleInterval: number | Ref<number>; throttleOptions: ThrottleOptions | Reactive<ThrottleOptions>; refreshOnWindowFocus: boolean | Ref<boolean>; refocusTimespan: number | Ref<number>; errorRetryCount: number | Ref<number>; errorRetryInterval: number | Ref<number>; };
-
refreshDeps
now supports passing a function that returns a value, a ref, a reactive object, or an array of any of these types. #166
-
service
no longer supports strings or objects. Users are expected to wrap their requests using other third-party libraries (such asaxios
) and provide aPromise
as theservice
function.const getUser = userName => { return axios.get('api/user', { params: { name: userName, }, }); }; useRequest(getUser, options);
-
formatResult
has been removed. Users are expected to format the final data in theirservice
function.const getUser = async () => { const results = await axios.get('api/user'); // Format the final data here return results.data; };
-
queryKey
has been removed, which means parallel mode is no longer supported. Users are expected to encapsulate each request action and UI into a component instead of putting all requests in the parent component. -
- When
manual=false
, every timeready
changes fromfalse
totrue
, a request will be automatically triggered with theoptions.defaultParams
parameter. - When
manual=true
, a request cannot be made as long asready
isfalse
.
- When
-
run
no longer returns aPromise
. UserunAsync
instead of the originalrun
function. -
Users can wrap
useRequest
withuseRequestProvider
themselves.
Name | Description | Type |
---|---|---|
manual | When set to true , you need to manually trigger loadMore or loadMoreAsync to make a request. The default value is false . |
boolean |
ready | When manual=false , every time ready changes from false to true , refresh will be automatically triggered. When manual=true , a request cannot be made as long as ready is false . |
Ref<boolean> | () => boolean |
refreshDeps | Automatically trigger refresh when changed. If refreshDepsAction is set, refreshDepsAction will be triggered. |
WatchSource<any> | WatchSource<any>[] |
refreshDepsAction | Triggered when refreshDeps changes. |
() => void |
debounceInterval | Process the request with a debounce strategy. | number | Ref<number> |
debounceOptions | Debounce parameters. | {leading: false, maxWait: undefined, trailing: true} |
throttleInterval | Process the request with a throttle strategy. | number | Ref<number> |
throttleOptions | Throttle parameters. | {leading: false, trailing: true} |
errorRetryCount | The number of error retries when an error occurs. | number | Ref<number> |
errorRetryInterval | The interval between error retries when an error occurs. | number | Ref<number> |
isNoMore | Determines whether there is more data. | (data?: R) => boolean |
onBefore | Triggered before service is executed. |
() => void |
onAfter | Triggered when service is completed. |
() => void |
onSuccess | Triggered when service is resolved. |
(data: R) => void |
onError | Triggered when service is rejected. |
(error: Error) => void |
Name | Description | Type |
---|---|---|
data | The data returned by service , which must include an array list , of type { list: any[], ...other } . |
Ref<R> |
dataList | The list array of data . |
Ref<R['list']> |
loading | Whether a request is in progress. | Ref<boolean> |
loadingMore | Whether more data is being loaded. | Ref<boolean> |
noMore | Whether there is more data, which needs to be used with options.isNoMore . |
Ref<boolean> |
error | The error returned by service . |
Error |
loadMore | Load more data, automatically capture exceptions, and handle them through options.onError . |
() => void |
loadMoreAsync | Load more data, return Promise , and handle errors on your own. |
() => Promise<R> |
refresh | Refresh and load the first page of data, automatically capture exceptions, and handle them through options.onError . |
() => void |
refreshAsync | Refresh and load the first page of data, return Promise , and handle errors on your own. |
() => Promise<R> |
mutate | Directly modify the result of data . |
(arg: (oldData: R) => R) => void | (newData: R) => void |
cancel | Cancel the request. | () => void |
1.2.4 (2022-01-21)
- replacing IIFE with UMD modules (2f05be8)
1.2.3 (2021-10-12)
1.2.2 (2021-10-06)
- Fix nullish operator is not transform
1.2.1 (2021-10-06)
1.2.0 (2021-05-22)
- usePagination: add
changePagination()
to modify bothcurrent
andpageSize
#43 (c3822f0) - add
onBefore()
andonAfter()
hooks #42 (135e76f) - add
reloading
to record the loading status ofreload()
#41 (5034f2c)
1.1.1 (2021-04-28)
- usePagination:
defaultParams.current
anddefaultParams.pageSize
should work ifmanual: true
(3ca5fd7), closes #40
1.1.0 (2021-04-19)
- useLoadMore: remove
mutate
ofuseLoadMore
(b935bcd)
1.0.5 (2021-03-22)
1.0.4 (2021-03-08)
- fix
useLoadMore
types (0e673bf)
1.0.3 (2021-03-06)
- concurrent request should have independent events (7511720)
usePagination
anduseLoadMore
support global config (8cceb1e)- usePagination: add
reload
function to reset paging info (def45e3) - useRequest: add
reload
function to clear thequeries
list (b64216b)
1.0.0-beta.11 (2021-03-03)
1.0.0-beta.10 (2021-03-02)
queries
changed fromshallowReactive
toreactive
(8f940a4)
1.0.0-beta.9 (2021-02-26)
- usePagination: does not support concurrent request (2c083ef)
- usePagination:
current
andpageSize
can modify and can trigger request, means you can directly usev-model
to bind them (ea5a238)
1.0.0-beta.8 (2021-02-24)
1.0.0-beta.7 (2021-01-11)
1.0.0-beta.6 (2020-12-31)
- add
isServer
to be compatible with node env 4f1c797 - modify the default value of
cacheTime
to 10 minutes a56ecb0