Answer the question
In order to leave comments, you need to log in
How to create your own useFetch?
Hello! I use vue3 + vite
How in Vue you can create your own useFetch so that you can insert both fetch and axios
in NuxtJs it's implemented like this
import { VueConstructor } from 'vue'
declare type ComponentInstance = InstanceType<VueConstructor>
interface Fetch {
(context: ComponentInstance): void | Promise<void>
}
declare const useFetch: (callback: Fetch) => {
fetch: () => void
fetchState: {
error: Error | null
pending: boolean
timestamp: number
}
$fetch: () => void
$fetchState: {
error: Error | null
pending: boolean
timestamp: number
}
}
useFetch(async () => {
await $axios.$get(`/api/v1/admin/tariffs`).then((response: any) => {
tariffs.value = response.data
})
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question