Vue project, routing control scheme, which contains page permission control, a single button permission empty

Install

npm install vue-auth-control --save

Copy the code

Usge

import {filterAsyncRouter, hasOneOf } from 'vue-auth-control' const role = ['admin']; Const asyncRouterMap = [{path: '/permission', Component: Layout, name: 'Permission test ', meta: {role: ['admin','super_editor']}, // children: [{path: 'index', Component: Permission, name: 'Permission ', meta: {role: [' admin ', 'super_editor]} / / permissions page need}}, {path:' * ', redirect: '/ 404', hidden: true}]; const filterRouter = filterAsyncRouter(asyncRouterMap, role ) const hasOneOfVal = hasOneOf(['admin', 'super_editor', ['admin']]) // trueCopy the code

API

filterAsyncRouter

This is used to filter routes and returns routes within this permission

  • parameter
/** * Recursively filter asynchronous routing table, @param {Array} asyncRouterMap @param {Array} roles */ filterAsyncRouter(asyncRouterMap, roles)Copy the code

hasOneOf

Returns false and true to check whether the elements in the array are present

/** * @param {Array} target Target Array * @param {Array} arr Array to be queried * @description Checks whether the Array to be queried contains at least one element in the target Array */ hasOneOf(target, arr)Copy the code