// stores/counter.js import { defineStore } from 'pinia'; import { ref, computed } from 'vue'; export const useCounterStore = defineStore('counter', () => { const count = ref(0); const double = computed(() => count.value * 2); function increment() { count.value++; } function reset() { count.value = 0; } return { count, double, increment, reset }; }); // main.js import { createApp } from 'vue'; import { createPinia } from 'pinia'; import App from './App.vue'; createApp(App).use(createPinia()).mount('#app'); +1 Reset Count: {{ store.count }} (double: {{ store.double }})
Count: {{ store.count }} (double: {{ store.double }})