diff --git a/packages/integrations/useAxios/index.ts b/packages/integrations/useAxios/index.ts index 680437932f0..3a4349d8bf3 100644 --- a/packages/integrations/useAxios/index.ts +++ b/packages/integrations/useAxios/index.ts @@ -1,8 +1,8 @@ import type { Ref, ShallowRef } from 'vue-demi' import { ref, shallowRef } from 'vue-demi' import { isString, until } from '@vueuse/shared' -import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, CancelTokenSource } from 'axios' -import axios from 'axios' +import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, CancelTokenSource } from 'axios' +import axios, { AxiosError } from 'axios' export interface UseAxiosReturn, D = any> { /** @@ -178,7 +178,14 @@ export function useAxios, D = any>(...args: any[]) error.value = undefined const _url = typeof executeUrl === 'string' ? executeUrl - : url ?? '' + : url ?? config.url + + if (_url === undefined) { + error.value = new AxiosError(AxiosError.ERR_INVALID_URL) + isFinished.value = true + return { then } + } + loading(true) instance(_url, { ...defaultConfig, ...typeof executeUrl === 'object' ? executeUrl : config, cancelToken: cancelToken.token }) .then((r: any) => {