use-api-vue-test
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

use-api-vue

Typescript class to work with AJAX requests. In order to use do the folowing steps:

1. Configure Provider

Add useApiProvider to the main component. And configure the global variables:

  • extraPostData: To add extra data in each POST request.
  • onError: To execute a function in each exception.
  • getError: Convert exceptions to your custom exception format.
  • requestConfig: AxiosRequestConfig

2. Use hooks like

  const { data, error, loading, send } = useGetRef<PostProps[], ErrorFormat>({ onCancelCallback: onUnmounted });
  send<PostsParams>('/posts', { category: [1,2,3] }); // It will send a request to the server
  return {
    data,
    error,
    loading,
    send,
  };

Using with Vue Query

This package can be used with vue-query.

  const result = useQuery<AxiosResponse<PostProps[]>, ErrorFormat>(
    'posts',
    () => get<PostProps[]>('/posts');
  );

Readme

Keywords

Package Sidebar

Install

npm i use-api-vue-test

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

42.2 kB

Total Files

5

Last publish

Collaborators

  • gradguard