一、说明
权限管理一般从路由权限、接口权限、页面权限、按钮权限四个角度去考虑。
我基于业务需求,实现了路由权限、页面权限、按钮权限。以下主要展示路由权限。
tips:(页面权限和按钮权限 需要在具体的页面or按钮中去实现;接口权限需要和后端去协商约定实现)
二、实现思路+源码:
1.router.ts
import store from "@/store/index";
import {
createRouter, createWebHashHistory } from "vue-router";
import {
AUTHORITY, ROLE } from "@/utils/constant";
const routerHistory = createWebHashHistory();
//配置路由列表
const router = createRouter({
history: routerHistory,
routes: [
{
path: "/",
redirect: "/log-in",
},
{
path: "/test",
component: Test,
},
{
path: "/log-in",
component: LogIn,
},
{
path: "/account",
component: Home,
children: [
{
path: "personal",
component: PersonalCenter,
},
{
path: "authority",
compone