Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useAxios): use shallowRef for resposne, data, and error #421

Merged
merged 4 commits into from Apr 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/integrations/useAxios/index.ts
@@ -1,4 +1,4 @@
import { Ref, ref } from 'vue-demi'
import { Ref, ref, shallowRef } from 'vue-demi'
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse, CancelTokenSource, AxiosInstance } from 'axios'

export interface UseAxiosReturn<T> {
Expand Down Expand Up @@ -42,12 +42,12 @@ export function useAxios<T = any>(url: string, ...args: any[]) {
instance = args[1]
}

const response = ref<any>(null) as Ref<AxiosResponse<T> | undefined>
const data = ref<any>(undefined) as Ref<T | undefined>
const response = shallowRef<AxiosResponse<T>>()
antfu marked this conversation as resolved.
Show resolved Hide resolved
const data = shallowRef<T>()
const finished = ref(false)
const loading = ref(true)
const canceled = ref(false)
const error = ref<AxiosError<T> | undefined>()
const error = shallowRef<AxiosError<T>>()

const cancelToken: CancelTokenSource = axios.CancelToken.source()
const cancel = (message?: string) => {
Expand Down