Skip to content

Commit

Permalink
feat: 🚀 修改 pinia 持久化插件
Browse files Browse the repository at this point in the history
以前 pinia-plugin-persist 插件存在bug
  • Loading branch information
Halsey committed Jun 13, 2022
1 parent 8537643 commit a7691ae
Show file tree
Hide file tree
Showing 7 changed files with 844 additions and 793 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"openxmlformats",
"pageable",
"Parens",
"persistedstate",
"Pinia",
"Prefixs",
"singleline",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cnpm install
npm install --registry=https://registry.npm.taobao.org
# 暂时没用,只是为了指定版本
npm i @element-plus/icons-vue@1.1.4 @vueuse/core@8.0.1 axios@0.27.2 echarts@5.3.0 echarts-liquidfill@3.1.0 element-plus@2.2.5 js-md5@0.7.3 nprogress@0.2.0 pinia@2.0.12 pinia-plugin-persist@1.0.0 qs@6.10.3 vue@3.2.25 vue-router@4.0.12 vue-i18n@9.1.9 vue3-seamless-scroll@1.2.0 --save
npm i @element-plus/icons-vue@1.1.4 @vueuse/core@8.0.1 axios@0.27.2 echarts@5.3.0 echarts-liquidfill@3.1.0 element-plus@2.2.5 js-md5@0.7.3 nprogress@0.2.0 pinia@2.0.12 pinia-plugin-persistedstate@1.6.1 qs@6.10.3 vue@3.2.25 vue-i18n@9.1.9 vue-router@4.0.12 vue3-seamless-scroll@1.2.0 --save
```

- **Run:**
Expand Down
1,609 changes: 832 additions & 777 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"js-md5": "^0.7.3",
"nprogress": "^0.2.0",
"pinia": "^2.0.12",
"pinia-plugin-persist": "^1.0.0",
"pinia-plugin-persistedstate": "^1.6.1",
"qs": "^6.10.3",
"vue": "^3.2.25",
"vue-i18n": "^9.1.9",
Expand Down
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { reactive, computed } from "vue";
import { GlobalStore } from "@/store";
// 配置element中英文
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import en from "element-plus/lib/locale/lang/en";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import en from "element-plus/es/locale/lang/en";
const globalStore = GlobalStore();
// 配置element按钮文字中间是否有空格
Expand Down
15 changes: 5 additions & 10 deletions src/config/piniaPersist.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { PersistOptions } from "pinia-plugin-persist";
import { PersistedStateOptions } from "pinia-plugin-persistedstate";

// pinia持久化参数配置
const piniaPersistConfig = (key: string) => {
const persist: PersistOptions = {
enabled: true,
strategies: [
{
key,
storage: localStorage
// storage: sessionStorage
}
]
const persist: PersistedStateOptions = {
key,
storage: window.localStorage
// storage: window.sessionStorage,
};
return persist;
};
Expand Down
4 changes: 2 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineStore } from "pinia";
import { GlobalState, ThemeConfigProp } from "./interface";
import { createPinia } from "pinia";
import piniaPersist from "pinia-plugin-persist";
import piniaPersistConfig from "@/config/piniaPersist";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";

// defineStore 调用后返回一个函数,调用该函数获得 Store 实体
export const GlobalStore = defineStore({
Expand Down Expand Up @@ -54,6 +54,6 @@ export const GlobalStore = defineStore({

// piniaPersist(持久化)
const pinia = createPinia();
pinia.use(piniaPersist);
pinia.use(piniaPluginPersistedstate);

export default pinia;

0 comments on commit a7691ae

Please sign in to comment.