🐞 fix: 修复登录状态问题

This commit is contained in:
alger
2024-01-04 10:18:00 +08:00
parent 820597e903
commit 3522011224
+11 -16
View File
@@ -61,22 +61,6 @@ const loadHotSearchKeyword = async () => {
hotSearchValue.value = data.data.realkeyword
}
watchEffect(() => {
const user = localStorage.getItem('user')
store.state.user = user ? JSON.parse(user) : null
})
watch(
() => store.state.user,
(newVal) => {
if (newVal) {
userSetOptions.value = USER_SET_OPTIONS
}else{
userSetOptions.value = USER_SET_OPTIONS.filter(item => item.key !== 'logout')
}
}
)
const loadPage = async () => {
const token = localStorage.getItem("token")
if (!token) return
@@ -85,6 +69,17 @@ const loadPage = async () => {
localStorage.setItem('user', JSON.stringify(data.profile))
}
watchEffect(() => {
loadPage()
if (store.state.user) {
userSetOptions.value = USER_SET_OPTIONS
} else {
userSetOptions.value = USER_SET_OPTIONS.filter(item => item.key !== 'logout')
}
})
const toLogin = () => {
router.push('/login')
}