Detailed changes
Use
vue-demi
to be compatible with vue2.Add
getCache
、setCache
、clearCache
.When caching is enabled, requests with the same
cacheKey
set will be reused.Add
runAsync
andrefreshAsync
, the original run no longer returns Promise.Add
definePlugin
to extend theuseReuqest
.In
debounce/throttle
mode,runAsync
can return current Promise.Add
useRequestProvider
to inject the options.Add
refreshDepsAction
option to customize the behavior afterrefreshDeps
is triggered.Add
loadingKeep
.refreshDepsAction
在manual=true
时,也会被refreshDeps
的改变而触发。The request library is no longer integrated by default, and service no longer supports string or object.
Remove
formatResult
. Migration helpRemove
queryKey
, that is, deleted concurrent request. Migration helprun
no longer returns Promise Migration helpdata
is no longer emptied when a request failsUpgraded
ready
behaviordata
anderror
changed toshallowRef
usePagination
removes thereload
method andreloading
. If you need the corresponding requirements, you can implement it yourself.Remove
RequestConfig
component. Migration helpRefactored
useLoadMore
. see alsocacheKey
Support passing in functions:cacheKey: (params?: P) => string
useRequest(getUser, { cacheKey: (params?: P): string => { if (params) { return `user-key-${params[0].name}`; } return ''; }, });
Some
options
support reactive as followstype ReactivityOptions = { loadingDelay: 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>; };
Migration help
formatResult
is deleted, and the service is expected to return the data in the final format. for example:
const getUser = async () => {
const results = await axios.get('api/user');
// Process the final data here
return results.data;
};