Skip to content

Commit

Permalink
🐞 fix: 修复登录状态问题
Browse files Browse the repository at this point in the history
  • Loading branch information
algerkong committed Jan 4, 2024
1 parent 820597e commit 3522011
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/layout/components/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
}
Expand Down

0 comments on commit 3522011

Please sign in to comment.