feat: add login state

This commit is contained in:
tim
2025-07-05 13:58:24 +08:00
parent f58a22e068
commit 94a1b4a237
2 changed files with 20 additions and 1 deletions

View File

@@ -12,7 +12,12 @@
</div> </div>
</div> </div>
<div class="header-content-right"> <div v-if="isLogin" class="header-content-right">
<div class="header-content-item-main" @click="goToProfile">个人中心</div>
<div class="header-content-item-secondary" @click="goToLogout">退出</div>
</div>
<div v-else class="header-content-right">
<div class="header-content-item-main" @click="goToLogin">登录</div> <div class="header-content-item-main" @click="goToLogin">登录</div>
<div class="header-content-item-secondary" @click="goToSignup">注册</div> <div class="header-content-item-secondary" @click="goToSignup">注册</div>
</div> </div>
@@ -21,6 +26,8 @@
</template> </template>
<script> <script>
import { isLogin } from '../utils/auth'
export default { export default {
name: 'HeaderComponent', name: 'HeaderComponent',
props: { props: {
@@ -29,6 +36,12 @@ export default {
default: true default: true
} }
}, },
computed: {
isLogin() {
return isLogin()
}
},
methods: { methods: {
goToHome() { goToHome() {
this.$router.push('/') this.$router.push('/')

View File

@@ -14,6 +14,12 @@ export function clearToken() {
localStorage.removeItem(TOKEN_KEY) localStorage.removeItem(TOKEN_KEY)
} }
export function isLogin() {
const token = getToken()
console.log('token', token)
return token !== null && token !== ''
}
export async function checkToken() { export async function checkToken() {
const token = getToken() const token = getToken()
if (!token) return false if (!token) return false