pinia store for counter

This commit is contained in:
Ulf Gebhardt 2023-11-23 04:58:08 +01:00
parent d0038cffb6
commit 5f529ebebe
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 18 additions and 1 deletions

View File

@ -1,3 +1,6 @@
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
export default createPinia()
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
export default pinia

14
src/stores/counter.ts Normal file
View File

@ -0,0 +1,14 @@
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', {
state: () => ({ count: 0 }),
actions: {
increment() {
this.count++
},
reset() {
this.count = 0
},
},
persist: true,
})