首页 > 解决方案 > 是否可以动态导入节点模块?

问题描述

我想知道是否可以动态导入通过 npm install 安装的模块。

就像是:

import("{ AsyncStorage } from react-native ???").then((module) => {
  // do something with module
});

到目前为止,我发现的所有示例都只是导入自写的 ES 模块......

标签: javascriptecmascript-6

解决方案


你应该这样做

import ("react-native").then(({AsyncStorage: module}) => {
  // Do something with the module
})


推荐阅读