显示选项取决于vue-router的不同条件

问题描述

我想根据访问组ID显示该选项。例如,访问组ID 1、2和3可以看到newstudent和allstudent的路径选项。除此之外,用户只能看到allstudent的选项。

import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Cookies from 'js-cookie'
export const constantRoutes = [
 {
    path: '/student',component: Layout,Meta: { title: 'Student',icon: 'example' },children: [
      {
        path: '/allstudent',component: () => import('@/views/student/class'),Meta: { title: 'All Student',},{
        path: '/newstudent',component: () => import('@/views/student/new'),Meta: { title: 'Create Student',hidden: 
          Cookies.get('accessgroupid') === '1' ||
          Cookies.get('accessgroupid') === '2' ||
          Cookies.get('accessgroupid') === '3'
          ? false : true
       }
    ]
 }
]

假设我具有访问组ID 1,当我登录页面时,我只会看到allstudent。我需要刷新页面,以便在侧栏上看到两个选项。

我将window.location.reload()放在我的login.vue中以解决该问题。但是我相信这可能不是解决此问题的最佳方法

我的代码对隐藏部分是否正确?

hidden: 
Cookies.get('accessgroupid') === '1' ||
Cookies.get('accessgroupid') === '2' ||
Cookies.get('accessgroupid') === '3'
? false : true

我如何不刷新页面以在边栏中显示正确的选项?

非常感谢您!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)