feat: Add persist option to useCounterStore

This commit is contained in:
严浩 committed 2024-09-11 10:47:54 +08:00
1 parent 3a8c685510
commit 8b4b361c7c
4 files changed
+577 -257

No files matched your search

+14 -8
View File
@@ -1,12 +1,18 @@
import { ref, computed } from 'vue';
import { defineStore } from 'pinia';
export const useCounterStore = defineStore('counter', () => {
const count = ref(0);
const doubleCount = computed(() => count.value * 2);
function increment() {
count.value++;
}
export const useCounterStore = defineStore(
'counter',
() => {
const count = ref(0);
const doubleCount = computed(() => count.value * 2);
function increment() {
count.value++;
}
return { count, doubleCount, increment };
});
return { count, doubleCount, increment };
},
{
persist: true,
},
);