From aa11c68bad7c03b7f1aed44356cc49e9668d55b8 Mon Sep 17 00:00:00 2001 From: zhang zhuo Date: Thu, 12 Jun 2025 18:12:41 +0800 Subject: [PATCH] pinia --- package.json | 1 + src/store/index.ts | 18 +++++------------- src/store/model/global.ts | 15 +++++++++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 7d5e059..db0c257 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "element-plus": "^2.9.10", "nprogress": "^0.2.0", "pinia": "^3.0.3", + "pinia-plugin-persistedstate": "^4.3.0", "sortablejs": "^1.15.6", "vue": "^3.5.14", "vue-i18n": "^11.1.5", diff --git a/src/store/index.ts b/src/store/index.ts index f6142c6..74319fa 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,15 +1,7 @@ -import {createStore} from 'vuex'; +import { createPinia } from "pinia" +import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' -const files = import.meta.glob('./model/*.ts', { - eager: true, - import: 'default' -}) +const store = createPinia() +store.use(piniaPluginPersistedstate) -const modules = {} -for (const path in files) { - modules[path.replace(/(\.\/model\/|\.ts)/g, '')] = files[path] -} - -export default createStore({ - modules -}); +export default store diff --git a/src/store/model/global.ts b/src/store/model/global.ts index 843a579..080e777 100644 --- a/src/store/model/global.ts +++ b/src/store/model/global.ts @@ -1,5 +1,12 @@ import tools from "@/utils/tools"; import config from "@/config"; +import {defineStore} from "pinia"; + +// const globalStore = defineStore('global', { +// state: () => { +// +// } +// }) export default { state: { @@ -13,16 +20,16 @@ export default { layoutTags: true }, mutations: { - SET_ismobile(state, key){ + SET_ismobile(state, key) { state.ismobile = key }, - SET_layout(state, key){ + SET_layout(state, key) { state.layout = key }, - TOGGLE_menuIsCollapse(state){ + TOGGLE_menuIsCollapse(state) { state.menuIsCollapse = !state.menuIsCollapse }, - TOGGLE_layoutTags(state){ + TOGGLE_layoutTags(state) { state.layoutTags = !state.layoutTags } }