0.0.3 • Published 2 years ago

use-api-vue-test v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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');
  );
0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago