From 5f529ebebed11d208ffd0b9dd5b46b6c749f705a Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 23 Nov 2023 04:58:08 +0100 Subject: [PATCH] pinia store for counter --- renderer/plugins/pinia.ts | 5 ++++- src/stores/counter.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/stores/counter.ts diff --git a/renderer/plugins/pinia.ts b/renderer/plugins/pinia.ts index f00b209..08b0373 100644 --- a/renderer/plugins/pinia.ts +++ b/renderer/plugins/pinia.ts @@ -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 diff --git a/src/stores/counter.ts b/src/stores/counter.ts new file mode 100644 index 0000000..e9482ad --- /dev/null +++ b/src/stores/counter.ts @@ -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, +})