Loading: true
Finished: false

TIP

available in add-on @vueuse/integrations

useAxios

wrapper for axios

Install

npm i axios

Usage

import { useAxios } from '@vueuse/integrations'

const { data, finished } = useAxios('/api/posts')

or use an instance of axios

import axios from 'axios'
import { useAxios } from '@vueuse/integrations'

const instance = axios.create({
  baseUrl: '/api'
})

const { data, finished } = useAxios('/posts', instance)

use an instance of axios with config options

import axios from 'axios'
import { useAxios } from '@vueuse/integrations'

const instance = axios.create({
  baseUrl: '/api'
})

const { data, finished } = useAxios('/posts', { method: 'POST' }, instance)

Type Declarations

export interface UseAxiosReturn<T> {
  response: Ref<AxiosResponse<T> | undefined>
  data: Ref<T | undefined>
  finished: Ref<boolean>
  loading: Ref<boolean>
  canceled: Ref<boolean>
  error: Ref<AxiosError<T> | undefined>
}
export declare function useAxios<T = any>(
  url: string,
  config?: AxiosRequestConfig
): UseAxiosReturn<T>
export declare function useAxios<T = any>(
  url: string,
  instance?: AxiosInstance
): UseAxiosReturn<T>
export declare function useAxios<T = any>(
  url: string,
  config: AxiosRequestConfig,
  instance: AxiosInstance
): UseAxiosReturn<T>

Source

SourceDemoDocs