Browse Source

fix(pinia): 处理小程序环境,pinia-plugin-persistedstate 不生效BUG

Burt 2 years ago
parent
commit
d17e8fa76d
3 changed files with 11 additions and 3 deletions
  1. 1 0
      .eslintrc.cjs
  2. 1 1
      src/store/count.ts
  3. 9 2
      src/store/index.ts

+ 1 - 0
.eslintrc.cjs

@@ -62,6 +62,7 @@ module.exports = {
     'no-plusplus': 'off',
     'no-shadow': 'off',
     'vue/multi-word-component-names': 'off',
+    '@typescript-eslint/no-explicit-any': 'off',
   },
   // eslint-import-resolver-typescript 插件,@see https://www.npmjs.com/package/eslint-import-resolver-typescript
   settings: {

+ 1 - 1
src/store/count.ts

@@ -1,4 +1,4 @@
-// src/store/use_count_store.ts
+// src/store/useCountStore.ts
 import { defineStore } from 'pinia'
 import { ref } from 'vue'
 

+ 9 - 2
src/store/index.ts

@@ -1,8 +1,15 @@
 // src/store/index.ts
 import { createPinia } from 'pinia'
-import piniaPersist from 'pinia-plugin-persistedstate' // 数据持久化
+import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
 
 const store = createPinia()
-store.use(piniaPersist)
+store.use(
+  createPersistedState({
+    storage: {
+      getItem: uni.getStorageSync,
+      setItem: uni.setStorageSync,
+    },
+  }),
+)
 
 export default store