this post was submitted on 11 Sep 2023
2 points (100.0% liked)
Vue.js
463 readers
10 users here now
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I understand that the cleanup thing is a bad idea. I had a really simple use case where i have a list of persons fetched from a database with their id, names and a link for each displayed using v-for. The link for each person is a router link which when clicked redirects to respective person/:id.
I want to display some stuff on this new component but didn't want to make the api call to fetch the person again from the database. This is why i wanted to pass the name as well in the props through the router link. But as you said maybe I should use pinia or some state management library for use cases like this?
Yep, definitely a job for pinia. But a second fetch doesn't seem unreasonable as well. The "list page" fetches an API endpoint to get a basic list of users, the "detail page" fetches another API endpoint returning a single user with the detailed information. If you are worried if you are doing to much requests, you also may have a look on Nuxt. With the SSR functionality it will save you multiple requests made.
I didn't have much idea about these so was trying to use the router itself. I'll look into nuxt and pinia and see which ones might be ideal for my use cases. Thanks a lot for answering!