pickstack

Vue + TanStack Query

Server state: caching, refetching, loading and error states. This page shows exactly what pickstack adds to a Vue project for TanStack Query: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.

$ npm create pickstack@latest my-app -- --framework vue --modules tanstack-query --yes
Customize in the configurator

Packages it adds

PackageVersionType
@tanstack/vue-query^5.108.4runtime

New files

public/stack.json
["Vue 3", "Vite", "TypeScript", "TanStack Query"]
src/api/stack.ts
/** Loads the stack list served from `public/stack.json`. */
export async function fetchStack(): Promise<string[]> {
  const response = await fetch(`${import.meta.env.BASE_URL}stack.json`);
  if (!response.ok) throw new Error(`Request failed: ${response.status}`);
  return response.json();
}
src/components/StackList.vue
<script setup lang="ts">
import { useQuery } from "@tanstack/vue-query";
import { fetchStack } from "../api/stack";

const { isPending, isError, data } = useQuery({
  queryKey: ["stack"],
  queryFn: fetchStack,
});
</script>

<template>
  <p v-if="isPending" class="text">Loading…</p>
  <p v-else-if="isError" class="text">Could not load the stack.</p>
  <p v-else class="text">Built with {{ data?.join(", ") }}.</p>
</template>

Changes to existing files

src/App.vue (changed)
 <script setup lang="ts"> import CounterCard from "./components/CounterCard.vue";+import StackList from "./components/StackList.vue"; </script>   <template>   <main class="app">     <h1 class="title">my-app</h1>     <CounterCard />+    <StackList />   </main> </template>  
src/main.ts (changed)
+import { VueQueryPlugin } from "@tanstack/vue-query"; import { createApp } from "vue"; import App from "./App.vue"; import "./assets/main.css";  +const app = createApp(App);+ +app.use(VueQueryPlugin);+ +app.mount("#app");−createApp(App).mount("#app");  

Project files

Related templates