examples/vue/star-wars-vue-router
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Vue Query Star Wars Example (Vue Router)#
A multi-page Star Wars app with films and characters, where each page fetches its own data.
Built with Vue Router.
How it works#
src/services/films/queries.ts,src/services/characters/queries.tsandsrc/services/planets/queries.tsdefinequeryOptionsfactories for SWAPI, keyed like['films', 'detail', filmId].filmsQueries.detailusesskipTokenwhen there is nofilmId.src/router.tsmaps each Vue Router route to a component and passes route params as props withprops: true.src/FilmList.vueandsrc/CharacterList.vuecalluseQuerywith a list factory, andsrc/FilmDetail.vueandsrc/CharacterDetail.vuepass a getter such asuseQuery(() => filmsQueries.detail(props.filmId))so the query follows the route param.- Detail pages render child components that each run their own
useQuery:src/FilmCharacter.vueper character,src/CharacterFilm.vueper film, andsrc/CharacterHomeworld.vuefor the character's homeworld. A film or character already loaded on one page comes from the cache on the next.
To run this example:
npm installnpm run dev