use-api-vue-test
v0.0.3
Published
AJAX request for Vue 3 using global configuration
Downloads
2
Readme
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');
);