class Utils { createdRouterConfig (router) { var menu = JSON.parse(localStorage.getItem("menu")); var RouterConfig = [] menu.forEach(v => { if (v.hasOwnProperty("children")) { v.children.forEach(k => { RouterConfig.push({ path: v.path + k.path, name: k.path.split("/")[1], component: () => import(`@/views${v.path}${k.path}.vue`), meta: { isLogin: true, keepAlive: false } }) }) } else { var fileName = v.path.replace( v.path.substring(1,2), v.path.substring(0,2).split("/")[1].toUpperCase() ) RouterConfig.push({ path: v.path, name: v.path.split("/")[1], component: () => import(`@/views${fileName}.vue`), meta: { isLogin: true, keepAlive: false } }) } }); var fa = [ { path: '/', name: 'layout', component: () => import(/* webpackChunkName: "Layout" */ '@/views/Layout.vue'), children: RouterConfig } ]; router.addRoutes(fa) } } export default new Utils();