Vue JS,如果用户通过身份验证显示不同的菜单

Dan*_*lci 2 vue.js vuejs2 nuxt.js

登录后,我在 store 和 localStorage 内设置了变量"authenticated" = true

如果authenticated==true并显示不同的菜单元素,我如何检查每个页面?

(我用的是ssr)

谢谢

M U*_*M U 5

  1. authenticated在登录时设置 Vuex 状态。
  2. 当您注销用户或应用程序正在启动并且您正在检查例如 JWT 是否仍然有效时,请务必清除。
  3. 在需要该状态的组件中设置计算变量。 computed() { authenticated () => { return this.$store.state.authenticated } }

  4. 在您的模板中使用它<v-if>

祝你好运!