amrnn90 / breeze-nuxt

An application / authentication starter kit frontend in Nuxt3 for Laravel Breeze.
MIT License
198 stars 33 forks source link

What's the best way to get data.data directly when using useLarafetch? #35

Open modstore opened 5 months ago

modstore commented 5 months ago

Not a problem, just though maybe you could guide me to the best way to do what I'm trying to do. All of my responses are wrapped in data , e.g a response could look like this:

{
  "data": [
    { "id": 1, ... },
    ...
  ],
  "total": 120,
  "page": 1,
  ...
}

So when I do a request using useLarafetch, to get the actual data attribute, I'm adding a computed property like this:

const { data, pending } = await useLarafetch(`/api/posts`)
const posts = computed(() => {
    return data.value.data
})

It would be nice if I could do this somehow, or make a custom fetch composable or something that would do something like this, but I'm not sure exactly how at the moment:

const { data: posts, page, total, pending } = await useLarafetch(`/api/posts`)

If you're able to point me in the right direction to do this, that would be great, thanks!