主要不同:
Vite 支持使用特殊的 import.meta.glob 函数从文件系统导入多个模块 代码: import React from 'react'; import loadable from '@loadable/component' const modules = import.meta.glob('./*/*.js') function bindRouter(list) { let arr = []; list.map((item) => { const path = `./${item.componentPath}.js` const ComponentNode = loadable(async () => { return modules[path](); }); if (item.menuChilds && item.menuChilds.length > 0) { if (item.isContainChildren) { arr.push({ path: item.pathRoute, element: <ComponentNode />, children: [...bindRouter(item.menuChilds)] }) } else { arr.push({ path: item.pathRoute, //element:<ComponentNode/> children: [...bindRouter(item.menuChilds)] }) } } else { arr.push({ path: item.pathRoute, element: <ComponentNode /> }) } }) return arr; } modules 打印效果如下: modules为一个对象,对应键名为路径名,对应值为一个函数返回import导入的组件 图片:modules.jpg ![]() 参考:https://www.pudn.com/news/6228cf499ddf223e1ad13fba.html |
|
最新喜欢:![]()
|