Count: {{ count }}
\nDouble: {{ doubleCount }}
\n \nuseStore — access store in component.
1<script setup>2import { useCounterStore } from "@/stores/counter"3import { storeToRefs } from "pinia"45const counterStore = useCounterStore()67// Option 1: direct access8console.log(counterStore.count)9counterStore.increment()1011// Option 2: destructuring with storeToRefs12const { count, doubleCount } = storeToRefs(counterStore)13const { increment } = counterStore14</script>1516<template>17 <div>18 <p>Count: {{ count }}</p>19 <p>Double: {{ doubleCount }}</p>20 <button @click="increment">Increment</button>21 </div>22</template>
Best practices: