Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
modstore opened this issue Jun 20, 2024 · 0 comments
Open

Comments

@modstore
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant