use-api-vue

AJAX request for Vue 3 using global configuration
2,438 2
Install
npm install use-api-vue
Latest Version:0.0.15
Vue:3
Older releases:2
License:MIT
Last Updated:Oct 24, 2026
Links: GitHub  ·  npm
Maintainer: gradguard

use-api-vue

Typescript functions to work with AJAX requests and vue-query.

Install

npm i use-api-vue

1. Configure Provider

Add useApiProvider to the main component (example here). 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

Using with Vue Query

This package can be used with vue-query.

  import { usePost, ApiResponse } from 'use-api-vue';

  const get = useGet({ onCancelCallback: onUnmounted });
  const result = useQuery<ApiResponse<PostProps[]>, ErrorFormat>(
    'posts',
    () => get<PostProps[]>('/posts');
  );
  // ErrorFormat is defined in `getError` inside the `useApiProvider`

Use hooks like

The params data, error, loading are reactive. send function is not reactive.

  import { useGetRef } from 'use-api-vue';

  const get = useGet({ onCancelCallback: onUnmounted });
  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,
  };

Related Packages

vue-axios-cors

This is http client vue.js plugin for cross origin access without preflight. It...

14,521 5
iot-axios2

kaifangpingtai-vue2

1,597
@epoundor/vue-fetch

The ultimate solution for making API calls in your Vue.js projects

1,592 7
vue-api-request

Control your API calls by using an amazing component which supports axios and vu...

4,076 125
@shaynekasai/v-fetch

A Vue directive to add AJAX to your app without the boilerplate

554

Version History

Version Released Vue License
0.0.15 ^3.2.41 MIT
0.0.14 ^3.2.41 MIT
0.0.13 ^3.2.41 MIT
0.0.12 ^3.2.41 MIT
0.0.11 ^3.2.33 || 2 MIT