소스 검색

处理登录人姓名动态更新问题

@dongkboy 3 달 전
부모
커밋
60da1f7b95
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      src/store/modules/user.ts

+ 2 - 2
src/store/modules/user.ts

@@ -22,7 +22,7 @@ const useUserStore = defineStore(
     const token = ref(localStorage.token ?? '')
     const avatar = ref(localStorage.avatar ?? '')
     const userInfo = ref(localStorage.userInfo ?? '')
-    const realName = userInfo.value ? JSON.parse(userInfo.value)?.name ?? '' : '';
+    const realName = computed(() => userInfo.value ? JSON.parse(typeof userInfo.value === 'string' ? userInfo.value : JSON.stringify(userInfo.value))?.name ?? '' : '');
     const permissions = ref<string[]>([])
     const staticRouter = ref<string[]>([])
     const isLogin = computed(() => {
@@ -111,4 +111,4 @@ const useUserStore = defineStore(
   },
 )
 
-export default useUserStore
+export default useUserStore