【问题标题】:Permission navigation in vuejs + laravel?vuejs + laravel中的权限导航?
【发布时间】:2021-10-12 20:54:42
【问题描述】:

我有一个广告系列列表页面。现在我想当用户登录时,如果他无权访问活动列表页面,它不会显示菜单并且不允许访问该网址?给我一些想法。谢谢

更新:我的问题与此类似:Router permission in vuejs + laravel?

【问题讨论】:

标签: laravel vue.js laravel-5 vuejs2


【解决方案1】:

您可以将状态存储在 Vuex 存储中。 然后在路由器中,您需要检查用户是否已登录,否则将用户重定向到登录页面。

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    // this route requires auth, check if logged in
    // if not, redirect to login page.
    if (!store.getters.isLoggedIn) {
      next({ name: 'Login' })
    } else {
      next() // go to wherever I'm going
    }
  } else {
    next() // does not require auth, make sure to always call next()!
  }
})

这是原始答案:https://stackoverflow.com/a/52663166/9318504

对于仅显示或隐藏导航栏或菜单等元素,您可以使用v-if

<Navigationbar v-if="userLoggedIn" />
<Menu v-if="userLoggedIn" />

【讨论】:

猜你喜欢
  • 2020-11-01
  • 2019-02-08
  • 2015-08-23
  • 1970-01-01
  • 2018-02-25
  • 2018-02-02
  • 1970-01-01
  • 2017-03-11
  • 2018-09-12
相关资源
最近更新 更多