Skip to content

Commit 33fa473

Browse files
authored
fix: 修复持久化的问题 (#316)
* fix: 修正首次进入页面时由于userStore数据还未初始化导致的白屏的问题 * Update user.ts fix: 优化逻辑
1 parent 0e25941 commit 33fa473

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/store/modules/user.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineStore } from 'pinia';
22
import { TOKEN_NAME } from '@/config/global';
3-
import { store } from '@/store';
3+
import { store, usePermissionStore } from '@/store';
44

55
const InitUserInfo = {
66
roles: [],
@@ -79,6 +79,14 @@ export const useUserStore = defineStore('user', {
7979
this.token = '';
8080
},
8181
},
82+
persist: {
83+
afterRestore: (ctx) => {
84+
if (ctx.store.roles && ctx.store.roles.length > 0) {
85+
const permissionStore = usePermissionStore();
86+
permissionStore.initRoutes(ctx.store.roles);
87+
}
88+
},
89+
},
8290
});
8391

8492
export function getUserStore() {

0 commit comments

Comments
 (0)