feat:接入pinia持久化存储
This commit is contained in:
@@ -1,23 +1,27 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import { createApp } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import App from "./App.vue";
|
||||
import router from "./router";
|
||||
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
|
||||
|
||||
import './assets/main.css'
|
||||
import '@/assets/styles/index.scss' // global css
|
||||
import "./assets/main.css";
|
||||
import "@/assets/styles/index.scss"; // global css
|
||||
|
||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
import directive from './directive' // directive
|
||||
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
|
||||
import directive from "./directive"; // directive
|
||||
|
||||
import "./permission"
|
||||
import "./permission";
|
||||
|
||||
const app = createApp(App)
|
||||
const app = createApp(App);
|
||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
app.component(key, component)
|
||||
}
|
||||
app.component(key, component);
|
||||
}
|
||||
|
||||
app.use(createPinia())
|
||||
const pinia = createPinia();
|
||||
pinia.use(piniaPluginPersistedstate);
|
||||
|
||||
app.use(pinia);
|
||||
directive(app);
|
||||
app.use(router)
|
||||
app.mount('#app')
|
||||
app.use(router);
|
||||
app.mount("#app");
|
||||
|
||||
@@ -1,22 +1,37 @@
|
||||
import {getAll} from '@/apis/configApi'
|
||||
import { defineStore } from 'pinia'
|
||||
const useConfigStore = defineStore('config',
|
||||
{
|
||||
state: () => ({
|
||||
data: []
|
||||
}),
|
||||
getters: {
|
||||
name:(state)=>state.data.filter(s=> s.configKey=='bbs.site.name').map(x=>x.configValue)[0],
|
||||
author:(state)=>state.data.filter(s=> s.configKey=='bbs.site.author').map(x=>x.configValue)[0],
|
||||
icp:(state)=>state.data.filter(s=> s.configKey=='bbs.site.icp').map(x=>x.configValue)[0],
|
||||
bottom:(state)=>state.data.filter(s=>s.configKey=='bbs.site.bottom').map(x=>x.configValue)[0]
|
||||
},
|
||||
actions: {
|
||||
// 登录
|
||||
async getConfig() {
|
||||
const response = await getAll();
|
||||
this.data = response.data.items;
|
||||
},
|
||||
},
|
||||
})
|
||||
import { getAll } from "@/apis/configApi";
|
||||
import { defineStore } from "pinia";
|
||||
const useConfigStore = defineStore("config", {
|
||||
state: () => ({
|
||||
data: [],
|
||||
}),
|
||||
getters: {
|
||||
name: (state) =>
|
||||
state.data
|
||||
.filter((s) => s.configKey == "bbs.site.name")
|
||||
.map((x) => x.configValue)[0],
|
||||
author: (state) =>
|
||||
state.data
|
||||
.filter((s) => s.configKey == "bbs.site.author")
|
||||
.map((x) => x.configValue)[0],
|
||||
icp: (state) =>
|
||||
state.data
|
||||
.filter((s) => s.configKey == "bbs.site.icp")
|
||||
.map((x) => x.configValue)[0],
|
||||
bottom: (state) =>
|
||||
state.data
|
||||
.filter((s) => s.configKey == "bbs.site.bottom")
|
||||
.map((x) => x.configValue)[0],
|
||||
},
|
||||
actions: {
|
||||
// 登录
|
||||
async getConfig() {
|
||||
const response = await getAll();
|
||||
this.data = response.data.items;
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
key: "configInfo",
|
||||
storage: window.sessionStorage,
|
||||
},
|
||||
});
|
||||
export default useConfigStore;
|
||||
|
||||
Reference in New Issue
Block a user