Created
May 28, 2022 07:11
-
-
Save theaungmyatmoe/ddadd563102f45e37846d9f2dc9c3594 to your computer and use it in GitHub Desktop.
Using custom hook/composable to fetch data in nuxt3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* It takes a URL and options, and returns a response object | |
* @param url - The URL to fetch. | |
* @param [options] - The options object that will be passed to the fetch function. | |
* @returns The return value of the useFetch hook. | |
*/ | |
import {useFetch, useRuntimeConfig} from "nuxt/app"; | |
export default function useFetchApi(url, options = {}) { | |
const config = useRuntimeConfig(); | |
return useFetch(url, { | |
...options, | |
baseURL: config.public.apiBase, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment