hx/store/count.ts

29 lines
461 B
TypeScript
Raw Permalink Normal View History

2024-10-18 18:09:15 +08:00
// src/store/useCountStore.ts
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useCountStore = defineStore(
'count',
() => {
const count = ref(0)
const increment = () => {
count.value++
}
const decrement = () => {
count.value--
}
const reset = () => {
count.value = 0
}
return {
count,
decrement,
increment,
reset,
}
},
{
persist: true,
},
)