递归方法
// asyncRoutes 本地所有的菜单路由
// menus 请求的角色的菜单路由
const _arrRoutes = (menus, localRoutes) => {
const list = []
localRoutes.filter(item => menus.some(ele => {
if (item.children && item.children.length) {
const routeChild = _arrRoutes(ele.children ?? [], item.children ?? [])
if (routeChild.length) item.children = routeChild
}
// 筛选条件
if (item.name === ele.path) {
list.push(item)
}
}))
return list
}
调用方法
const routes = _arrRoutes(menus, asyncRoutes)
console.log(routes, '筛选后的数据')