Vue 3 + Pinia - best way to handle API filtering, fetching, sorting, pagination #9606
Unanswered
LadIQe
asked this question in
Help/Questions
Replies: 1 comment
-
This repo is the best example I've found for using pinia and vue-query together https://github.com/elvisss/vue-clients-useQuery-pinia/blob/master/src/clients/composables/useClients.ts |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello community, sorry for my too long post, but Im struggling big time.
Im again working with my love (Vue) after 1yr break (had to work with angular).
So I have started to learn everything from scratch and also trying to code something. But, I found some new things, which are new to me and now Im confused (maybe because of angular, who knows).
What is the best way to handle API calls with sorting, filtering and pagination?
I want to store pagination and filters in Pinia store (and url as query params), something like that
Now, I have parent (page) component, where I "install" store like this and pass down store state through props to my child components.
const receiverStore = useReceiverStore()
Now I have child component with table and filters (inputs, selects, etc), with props definition
Here is table with filtering with some description
Now thing is, that when I change some filters, my table (quasar table) should fire
@reguest
emit, which collects all filters and pagination like thisThis emit is handled by parent component, which pushes this filters to route query
router.push({ query: filters })
which are then collected by router and passed down as props to parent (page) component
In parent component, there is watchEffect, which sets filters in Pinia store and call fetch
Now question is, is this anti-pattern? I was working with angular where this was preferred way to handle url filters (I was new to angular, so I didnt know if this is the best way to work with) and this pattern somehow got its way to my test project.
Thank you
Beta Was this translation helpful? Give feedback.
All reactions