2 回答

TA贡献1806条经验 获得超5个赞
首先,在EM6上使用导入/导出时,您需要小心,因为现在您无法导出js文件顶级范围之外的任何位置,并且它的一般处理方式与EM5不同。
现在有了问题。我看到您正在从ForEach循环/函数内部导出组件,并且在EM5中完全可以正常工作,但与EM6完全不同,并且至少在不期望组件数量的情况下,我看到了两种解决问题的方法迅速增长:
调用一个返回组件并导出它的函数,对每个组件执行此操作。应该看起来像这样:
./componentsFile.js
exports.component1 = () => { /*code...*/ return component }
exports.component2 = () => { /*code...*/ return component }
./renderingFile.js
import { component1, component2 } from './componentsFile.js'
/* use the components that you get from the return... */
另一种方法是构建一个对象,其中的字段是组件。并在导入时对其进行销毁。
./componentsFile.js
const component1 = /*Create the component*/
const component2 = /*Create the component*/
exports.object = {
component1,
component2,}
./renderingFile.js
import { component1, component2 } from './componentsFile.js'
/*Use the components...*/
我认为您可以通过以下两种方式来获得想法。

TA贡献1744条经验 获得超4个赞
添加回答
举报