Open yangmeiooo opened 5 years ago
后端返回的component是字符串,这里的主要工作就是讲这个字符串转为一个对象
感谢你的回答_ 1.let { //这里定义一个对象吗??? path, component, name, meta, iconCls, children } = router; 2.component(resolve){ }.这2个地方我看不懂,这是ES6的语法还是那一部分的知识?
2.component(resolve){ } 我的理解是将组件名称(字符串)转换为特定组件对象返回
@w306026355 感谢你的回答,只不过我2component(resolve)有点不能接受而已。
//干的就是从后台请求的数据拼接成一个路由信息对象而已 export const formatRoutes = (routes)=> { let fmRoutes = []; routes.forEach(router=> { let { //这里定义一个对象吗??? path, component, name, meta, iconCls, children } = router; //这不是形参吗?重新定义对象赋值给形参吗? //这是什么神仙写法 console.log("------------>"); console.log(router); if (children && children instanceof Array) { children = formatRoutes(children); } let fmRouter = { path: path, component(resolve){ //component(resolve)这是什么方法调用?没看懂?这也没有定义component方法啊? if (component.startsWith("Home")) { require(['../components/' + component + '.vue'], resolve) } else if (component.startsWith("Emp")) { require(['../components/emp/' + component + '.vue'], resolve) } else if (component.startsWith("Per")) { require(['../components/personnel/' + component + '.vue'], resolve) } else if (component.startsWith("Sal")) { require(['../components/salary/' + component + '.vue'], resolve) } else if (component.startsWith("Sta")) { require(['../components/statistics/' + component + '.vue'], resolve) } else if (component.startsWith("Sys")) { require(['../components/system/' + component + '.vue'], resolve) } }, name: name, iconCls: iconCls, meta: meta, children: children }; fmRoutes.push(fmRouter); }); console.log("------------>"); console.log(fmRoutes); return fmRoutes;