Detailed changes

  • Use vue-demi to be compatible with vue2.

  • Add getCachesetCacheclearCache.

  • When caching is enabled, requests with the same cacheKey set will be reused.

  • Add runAsync and refreshAsync, the original run no longer returns Promise.

  • Add definePlugin to extend the useReuqest.

  • In debounce/throttle mode, runAsync can return current Promise.

  • Add useRequestProvider to inject the options.

  • Add refreshDepsAction option to customize the behavior after refreshDeps is triggered.

  • Add loadingKeep.

  • refreshDepsActionmanual=true 时,也会被 refreshDeps 的改变而触发。

  • The request library is no longer integrated by default, and service no longer supports string or object.

  • Remove formatResult. Migration help

  • Remove queryKey, that is, deleted concurrent request. Migration help

  • run no longer returns Promise Migration help

  • data is no longer emptied when a request fails

  • Upgraded ready behavior

  • data and error changed to shallowRef

  • usePagination removes the reload method and reloading. If you need the corresponding requirements, you can implement it yourself.

  • Remove RequestConfig component. Migration help

  • Refactored useLoadMore. see also

  • cacheKey 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 follows

    type 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

  1. 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;
};
  1. The original concurrent mode of queryKey is deleted. It is expected that each request action and UI will be encapsulated as a component instead of placing all requests in the parent.

  2. run no longer returns a Promise. use runAsync instead of the original run.

  3. Can be wrapped by useRequestProvider by yourself.

Last Updated: 7/6/2023, 3:23:08 AM
Contributors: John