Samuelreichoer
Custom Fetch Types not align
This was the solution:
import { defu } from 'defu'
import type { UseFetchOptions } from '#app'
export function useCraftFetch<T>(
url: string | (() => string),
options?: UseFetchOptions<T>,
) {
const { authToken } = useRuntimeConfig().public.craftcms
const defaults: UseFetchOptions<T> = {
headers: {
Authorization: authToken,
},
}
const params = defu(options, defaults)
return useFetch(url, params)
}
23 replies
Custom Fetch Types not align
@kapa.ai Now I get folliwing ts error
Argument of type 'string | Request | Ref<string | Request, string | Request> | (() => string | Request)' is not assignable to parameter of type 'NitroFetchRequest'.
Type 'Ref<string | Request, string | Request>' is not assignable to type 'NitroFetchRequest'.ts(2345)
in that line on url () => $fetch<T>(url, {
23 replies
runWithContext not working as expected
@kapa.ai When I return it like that
return {
title: computed(() => seoMaticData.value?.title),
metaTags: computed(() => seoMaticData.value?.metaTags),
linkTags: computed(() => seoMaticData.value?.linkTags),
jsonLd: computed(() => seoMaticData.value?.jsonLd),
}
and import it like that
const { metaTags, title, linkTags, jsonLd} = await useCraftSeoMatic()
I get an ts error that
Vue: Property metaTags does not exist on type
{ title: ComputedRef<string | undefined>; metaTags: ComputedRef<Record<string, any>[] | undefined>; linkTags: ComputedRef<Record<string, any>[] | undefined>; jsonLd: ComputedRef<...>; } | undefined
16 replies
runWithContext not working as expected
When I return it like that
return {
title: computed(() => seoMaticData.value?.title),
metaTags: computed(() => seoMaticData.value?.metaTags),
linkTags: computed(() => seoMaticData.value?.linkTags),
jsonLd: computed(() => seoMaticData.value?.jsonLd),
}
and import it like that
const { metaTags, title, linkTags, jsonLd} = await useCraftSeoMatic()
I get an ts error that
Vue: Property metaTags does not exist on type
{ title: ComputedRef<string | undefined>; metaTags: ComputedRef<Record<string, any>[] | undefined>; linkTags: ComputedRef<Record<string, any>[] | undefined>; jsonLd: ComputedRef<...>; } | undefined
16 replies
runWithContext not working as expected
@kapa.ai Alright so I use this useFetch and want to return all of these properties without loosing reacitvity
const { data: seoMaticData, error } = await useFetch(apiEndpoint, {
transform: (seoMaticData: SeoData) => {
if (!seoMaticData || typeof seoMaticData !== 'object') {
console.error('Transformation of SEOmatic data failed, please verify that the SEOmatic endpoint is working correctly')
return undefined
}
return {
title: seoMaticData.MetaTitleContainer?.title?.title ?? '',
metaTags: generateMetaTags(seoMaticData.MetaTagContainer),
linkTags: generateLinkTags(seoMaticData.MetaLinkContainer),
jsonLd: seoMaticData.MetaJsonLdContainer ?? {},
};
},
})
how do I do this?
16 replies
Prerendering not working
@kapa.ai Transform failed with 1 error:
/Users/samuel/Documents/Private-Projekte/00-repos/nuxt-craftcms/src/runtime/composables/useComposables.ts:13:2: ERROR: Unexpected "const" the error happens at the getFullUrl var
103 replies
Prerendering not working
@kapa.ai Nein nitro läuft auf local host somit ist dieses composable
export function useCraftFullUrl() {
const route = useRoute()
const fullUrl = ref(import.meta.server ? useRequestURL().href : window.location.href)
watch(route, () => {
fullUrl.value = import.meta.server ? useRequestURL().href : window.location.href
})
return fullUrl
}
falsch und kann nicht den richtigen url herausfinden und dann nicht den richtigen query bauen
103 replies
Prerendering not working
Nein nitro läuft auf local host somit ist dieses composable
export function useCraftFullUrl() {
const route = useRoute()
const fullUrl = ref(import.meta.server ? useRequestURL().href : window.location.href)
watch(route, () => {
fullUrl.value = import.meta.server ? useRequestURL().href : window.location.href
})
return fullUrl
}
falsch und kann nicht den richtigen url herausfinden und dann nicht den richtigen query bauen
103 replies
Prerendering not working
@kapa.ai Okey ich habe jetzt den fehler gefunden, der nitro host ist localhost und nicht wie gewünscht 'https://craft-nuxt-starter.ddev.site/' wie stelle ich das um?
103 replies
Prerendering not working
Okey ich habe jetzt den fehler gefunden, der nitro host ist localhost und nicht wie gewünscht 'https://craft-nuxt-starter.ddev.site' wie stelle ich das um?
103 replies
Prerendering not working
@kapa.ai that's the code of useCraftQuery
import type { ElementType } from 'js-craftcms-api'
import { useCraftUrlBuilder } from 'vue-craftcms'
import { useAsyncData } from '#imports'
function fetchFn(url: string) {
return useAsyncData(
craftcms:${url}
, () => $fetch(url))
}
export function useCraftQuery<T extends ElementType>(elementType: T) {
const queryBuilder = useCraftUrlBuilder(elementType)
return {
...queryBuilder,
one() {
const url = queryBuilder.buildUrl('one')
return fetchFn(url)
},
all() {
const url = queryBuilder.buildUrl('all')
return fetchFn(url)
},
}
}103 replies