#Which of these is the correct way to fetch?

2 messages · Page 1 of 1 (latest)

boreal cedar
#

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}`,
  )

B: data is: globalThis.Ref<Simplify<SerializeObject<{..... /> (correct)

  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

😕

arctic sail
#

the first one. params is for query params