feat: 添加 Pinia 插件支持并重构主应用初始化逻辑
All checks were successful
/ depcheck (push) Successful in 1m26s
/ playwright (push) Successful in 3m25s
/ build-and-deploy-to-vercel (push) Successful in 3m56s

This commit is contained in:
严浩
2024-12-19 23:09:17 +08:00
parent 5f81c647fa
commit 487b6bd315
3 changed files with 10 additions and 5 deletions

View File

@ -0,0 +1,22 @@
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++;
}
return { count, doubleCount, increment };
},
{
persist: true,
},
);
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useCounterStore, import.meta.hot));
}

View File

@ -0,0 +1,7 @@
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
export function setupPinia(app: import('vue').App) {
app.use(createPinia().use(piniaPluginPersistedstate));
}
export * from './counter';