import store from '@/store' import generateBtnPermission from '../auth/generateBtnPermission' const newRoutes = [] function createMeta(item) { let meta = { title: item.name } return meta } function createRoute(data) { data.map(e => { const { path } = e // 有path则添加到路由里 path && newRoutes.push({ path, meta: createMeta(e) }) // 递归生成路由集合 e.children && e.children.length && createRoute(e.children) }) } export default function(data, path) { generateBtnPermission(data); createRoute(data); store.dispatch("auth/addRoutes", newRoutes); }