fix: 修复持久化的问题 (#316)

* fix: 修正首次进入页面时由于userStore数据还未初始化导致的白屏的问题

* Update user.ts

fix: 优化逻辑
This commit is contained in:
PDieE 2022-09-17 16:40:11 +08:00 committed by Uyarn
parent 094339b1c4
commit 07f30597d0

View File

@ -1,6 +1,6 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { TOKEN_NAME } from '@/config/global'; import { TOKEN_NAME } from '@/config/global';
import { store } from '@/store'; import { store, usePermissionStore } from '@/store';
const InitUserInfo = { const InitUserInfo = {
roles: [], roles: [],
@ -79,6 +79,14 @@ export const useUserStore = defineStore('user', {
this.token = ''; this.token = '';
}, },
}, },
persist: {
afterRestore: (ctx) => {
if (ctx.store.roles && ctx.store.roles.length > 0) {
const permissionStore = usePermissionStore();
permissionStore.initRoutes(ctx.store.roles);
}
},
},
}); });
export function getUserStore() { export function getUserStore() {