Typescript class to work with AJAX requests. In order to use do the folowing steps:
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
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,
};
This package can be used with vue-query.
const result = useQuery<AxiosResponse<PostProps[]>, ErrorFormat>(
'posts',
() => get<PostProps[]>('/posts');
);