我正在嘗試檢查是否有經過身份驗證的用戶以呈現側邊欄和標題。如果未通過身份驗證,則不會呈現側邊欄和標題以僅顯示登錄或注冊。但是我的 this.auth 資料在我重新加載頁面之前不會更新。我知道 vuejs 上可能有一個功能會更頻繁地更新這個變數?(我的側邊欄包含用于加載其余組件的路由器鏈接,但是當我單擊路由器鏈接時 this.auth 不會更新)
編輯:使用計算屬性解決了它。
<template>
<v-app>
<header-component v-if="auth" />
<sidebar-component v-if="auth" />
<router-view></router-view>
</v-app>
</template>
<script>
import Sidebar from "./components/Sidebar"
import Header from "./components/Header"
export default{
name: 'App',
components: {
'sidebar-component': Sidebar,
'header-component': Header,
},
computed: {
auth ()
{
return (!localStorage.getItem("auth")) ? false : true
}
}
}
</script>
uj5u.com熱心網友回復:
您可以洗掉資料中的 auth 宣告,并像這樣使用計算:
computed {auth (){return (!localStorage.getItem("auth")) ? false : true}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/381415.html
