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

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

* Update user.ts

fix: 优化逻辑
This commit is contained in:
PDieE 2022-09-17 16:40:11 +08:00 committed by GitHub
parent 0e259413ca
commit 33fa473761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import { defineStore } from 'pinia';
import { TOKEN_NAME } from '@/config/global';
import { store } from '@/store';
import { store, usePermissionStore } from '@/store';
const InitUserInfo = {
roles: [],
@ -79,6 +79,14 @@ export const useUserStore = defineStore('user', {
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() {