Defining a Store
import { defineStore } from 'pinia';
const useCounterStore = defineStore('counterStore', {
state: () => ({
counter: 0
}),
getters: {
doubleCounter() {
return this.counter * 2;
},
tripleCounter: (state) => state.counter * 3
},
actions: {
incrment() {
this.counter++;
}
}
});
Using that store in a component
// ..... more component things .....
const store = useStore();
const doubleValue = computed(() => store.doubleCount);
function inc() {
store.increment();
}
// .... even mor ecomponent things ....