ES6 使用命名空间动态导入?
ES6 Dynamic importing with namespace?
使用动态导入时,是否可以像常规导入一样定义要导入的内容?
例如:
import Person from '/classes.js'
作为动态:
await import('Person from /classes.js') //Incorrect obviously
动态导入将为您提供模块内的所有内容。您可以使用解构来提取您想要的部分。
const { Person } = await import('/classes.js');
当你需要导入一些特定的文件时,你可以试试这个。
const moduleSpecifier = '/classes.js';
import(moduleSpecifier)
.then(someModule => someModule.myFucntion());
使用动态导入时,是否可以像常规导入一样定义要导入的内容?
例如:
import Person from '/classes.js'
作为动态:
await import('Person from /classes.js') //Incorrect obviously
动态导入将为您提供模块内的所有内容。您可以使用解构来提取您想要的部分。
const { Person } = await import('/classes.js');
当你需要导入一些特定的文件时,你可以试试这个。
const moduleSpecifier = '/classes.js';
import(moduleSpecifier)
.then(someModule => someModule.myFucntion());