最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ES6 Dynamic importing with namespace? - Stack Overflow

programmeradmin4浏览0评论

When using dynamic imports, can I define what I want to import like regular imports?

For example:

import Person from '/classes.js'

As dynamic:

await import('Person from /classes.js') //Incorrect obviously

When using dynamic imports, can I define what I want to import like regular imports?

For example:

import Person from '/classes.js'

As dynamic:

await import('Person from /classes.js') //Incorrect obviously
Share Improve this question asked Nov 8, 2018 at 16:01 MojimiMojimi 3,18112 gold badges65 silver badges133 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Dynamic imports will hand you everything from within the module. You can use destructuring the extract the pieces you want.

const { Person } = await import('/classes.js');

You can try this when you need to import some specific file.

const moduleSpecifier = '/classes.js';
import(moduleSpecifier)
.then(someModule => someModule.myFucntion());
发布评论

评论列表(0)

  1. 暂无评论