From 3522011224b597aabca3d84298f68287ae0b1e54 Mon Sep 17 00:00:00 2001 From: alger Date: Thu, 4 Jan 2024 10:18:00 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=8A=B6=E6=80=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/SearchBar.vue | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/layout/components/SearchBar.vue b/src/layout/components/SearchBar.vue index 5e83a3c..d30c95a 100644 --- a/src/layout/components/SearchBar.vue +++ b/src/layout/components/SearchBar.vue @@ -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') }