2024-04-08 10:58:37 +08:00
|
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
|
|
|
|
// 你可以任意命名 `defineStore()` 的返回值,但最好使用 store 的名字,同时以 `use` 开头且以 `Store` 结尾。
|
|
|
|
|
// (比如 `useUserStore`,`useCartStore`,`useProductStore`)
|
|
|
|
|
// 第一个参数是你的应用中 Store 的唯一 ID。
|
|
|
|
|
export const useAlertsStore = defineStore('alerts', {
|
|
|
|
|
// 其他配置...
|
|
|
|
|
})
|
|
|
|
|
export const useCounterStore = defineStore('counter', {
|
|
|
|
|
state: () => ({ count: 0 }),
|
|
|
|
|
getters: {
|
|
|
|
|
double: (state) => state.count * 2,
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
|
|
|
|
increment() {
|
|
|
|
|
this.count++
|
|
|
|
|
},
|
|
|
|
|
decrement() {
|
|
|
|
|
this.count--
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-04-08 11:02:21 +08:00
|
|
|
|
// 开启缓存
|
|
|
|
|
persist: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
strategies: [
|
|
|
|
|
{
|
|
|
|
|
key: 'counter',
|
|
|
|
|
storage: localStorage,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2024-04-08 10:58:37 +08:00
|
|
|
|
})
|