[英]Show different sidebar items or hide some components based on user-role after login (VUEJS)
How can I go about populating a sidebar with appropriate menu items based on user role?.如何根据用户角色使用适当的菜单项填充侧边栏? i need to show and hide some components based on user or admin login in vuejs.
我需要根据 vuejs 中的用户或管理员登录显示和隐藏一些组件。
One way would be in the created
life-cycle function, get the user_role
, then have a computed
property compute what should be shown in the sidebar.一种方法是在
created
的生命周期 function 中,获取user_role
,然后让computed
属性计算应在侧栏中显示的内容。 This way you can change the users and get new sidebars each time the component is rendered.这样,您可以在每次渲染组件时更改用户并获得新的侧边栏。
You have to check the user role and add a 'permission' field in menu.您必须检查用户角色并在菜单中添加“权限”字段。
Here is an example:这是一个例子:
{
id: "dashboard",
icon: "iconsminds-monitor-analytics",
label: "menu.dashboard",
to: "/app/dashboard",
permission: ["ROLE_ADMIN", "ROLE_TECHNICIAN", "ROLE_DOCTOR"],
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.