N
Nuxtβ€’3mo ago
Ryan The Temp

Which of these is the correct way to fetch?

When is the correct way to do a $fetch with parameters: A: data is: globalThis.Ref<unknown, unknown>
const { data } = await useAsyncData("project", () =>
$fetch(`/api/project/${id}`,
)
const { data } = await useAsyncData("project", () =>
$fetch(`/api/project/${id}`,
)
B: data is: globalThis.Ref<Simplify<SerializeObject<{..... /> (correct)
const { data } = await useAsyncData("project", () =>
$fetch(`/api/project/:id`, { params: { id } }),
)
const { data } = await useAsyncData("project", () =>
$fetch(`/api/project/:id`, { params: { id } }),
)
A works if I just cast everything to any, but I lose all types. B also works, but it looks weird that I have to have an :id and declare a params πŸ˜•
2 Replies
manniL
manniLβ€’3mo ago
the first one. params is for query params
Ryan The Temp
Ryan The TempOPβ€’3mo ago
Hmm, why is type information lost though?
Want results from more Discord servers?
Add your server