Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

vue 简单动态路由

场景:

  1. 项目有两个固定角色,a、b
  2. a的路由为
{
        path: '/fileManagement',
        component: Layout,
        redirect: '/fileManagement/index',
        name: 'fileManagement',
        meta: {
            title: '标题
            icon: 'user',
            role: ['admin', 'other'],
        },
        children: [
            {
                path: 'file',
                component: () => import('@/views/fileManagement/file/index'),
                name: 'pointManagement',
                meta: { title: '子标题 'admin' ] }
            },
            {
                path: 'venue',
                component: () => import('@/views/fileManagement/venue/list'),
                name: 'venueManagement',
                meta: { title: '子标题 'role:['admin']
            },
        ]
    },

3.的路由和a格式一样


那么如何根据登录的角色a或b,在菜单展示不同的路由呢?
我的想法是根据登录后的角色id,来判断显示哪个角色的菜单,然后addRouters进去。
但是具体写法没转过来,请大神赐教


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

为什么一定要这么写?直接给全部路由,然后在路由拦截器里判断有没有访问的权限不行吗?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...