Composables
useCraftFetch
Learn how to use the useCraftFetch composable.
This composable adds a useFetch
wrapper to query data with the provided Bearer token in your nuxt.config.ts
.
Usage
const { baseUrl } = useRuntimeConfig().public.craftcms
const apiUrl = `${baseUrl}/v1/api/queryApi/customQuery?elementType=navigation&handle=mainNavigation&all=1`
const { data: links, error } = useCraftFetch(apiUrl)
if (error.value) {
console.log(error.value)
}
Note
To see all the available options please refer to the official useFetch docs.
Type
function useCraftFetch<T>(
url: Ref<string> | string | (() => string),
options?: UseFetchOptions<T>,
): ReturnType<typeof useFetch<T>>