pickstack

Vue + Pinia

The official Vue store, using setup-store syntax. This page shows exactly what pickstack adds to a Vue project for Pinia: 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 pinia --yes
Customize in the configurator

Packages it adds

PackageVersionType
@vue/devtools-api^8.2.1runtime
pinia^4.1.0runtime

New files

src/stores/counter.ts
import { defineStore } from "pinia";
import { ref } from "vue";

export const useCounterStore = defineStore("counter", () => {
  const count = ref(0);

  function increment() {
    count.value++;
  }

  function decrement() {
    count.value--;
  }

  return { count, increment, decrement };
});

Changes to existing files

src/components/CounterCard.vue (changed)
 <script setup lang="ts">+import { useCounterStore } from "@/stores/counter";−import { ref } from "vue";  +const counter = useCounterStore();−const count = ref(0); </script>   <template>   <div class="card">+    <p class="count">{{ counter.count }}</p>−    <p class="count">{{ count }}</p>     <div class="row">+      <button type="button" class="btn" @click="counter.decrement()">-1</button>+      <button type="button" class="btn" @click="counter.increment()">+1</button>−      <button type="button" class="btn" @click="count--">-1</button>−      <button type="button" class="btn" @click="count++">+1</button>     </div>   </div> </template>⋯ 1 unchanged lines
src/main.ts (changed)
+import { createPinia } from "pinia"; import { createApp } from "vue"; import App from "./App.vue"; import "./assets/main.css";  +const app = createApp(App);+ +app.use(createPinia());+ +app.mount("#app");−createApp(App).mount("#app");  

Project files

Related templates