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 --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@vue/devtools-api | ^8.2.1 | runtime |
pinia | ^4.1.0 | runtime |
New files
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
<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
+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
.gitignoreREADME.mdenv.d.tsindex.htmlpackage.jsonsrc/App.vuesrc/assets/main.csssrc/components/CounterCard.vuesrc/main.tssrc/stores/counter.tstsconfig.app.jsontsconfig.jsontsconfig.node.jsonvite.config.ts