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 --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@tanstack/vue-query | ^5.108.4 | runtime |
New files
["Vue 3", "Vite", "TypeScript", "TanStack Query"]
/** 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();
}
<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
<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>
+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
.gitignoreREADME.mdenv.d.tsindex.htmlpackage.jsonpublic/stack.jsonsrc/App.vuesrc/api/stack.tssrc/assets/main.csssrc/components/CounterCard.vuesrc/components/StackList.vuesrc/main.tstsconfig.app.jsontsconfig.jsontsconfig.node.jsonvite.config.ts