sách gpt4 ăn đã đi

javascript - 如何在 Javascript/ReactJs/React Native 中动态导入模块

In lại Tác giả: Walker 123 更新时间:2023-12-01 00:21:53 26 4
mua khóa gpt4 giày nike

我想从路径动态导入模块 importPath vượt quaProps设置。

var importPath;

class MainComponent extends Component {
state = {}
render() {
// Set var importPath = "path_to_module here;"
// importPath = this.props.myModulePath
return (
);
}
}

export default MainComponent;

Sau đó:

class ComponentToImport extends Component {
ToastExample: (async () => {
await import (this.props.revPath)
})()

async sayHiFromJava() {
this.state.ToastExample.showJ('Awesome', ToastExample.SHORT);
}

render() {
return ();
}
}

Làm thế nào tôi có thể giải quyết vấn đề này?

提前谢谢大家。

如何附加 ToastExamplehiện hữuimport ToastExample from importPath;await import("importPath");这样我就可以return();

gia hạn

我已经尝试过:

class ComponentToImport extends Component {
ToastExample: (async () => {
await import (this.props.revPath)
})()

async sayHiFromJava() {
this.state.ToastExample.showJ('Awesome', ToastExample.SHORT);
}

render() {
return ();
}
}

但我收到错误:

error: bundling failed: index.js: index.js:Invalid call at line 28: import(_this.props.myComponentPath)

câu trả lời hay nhất

我想这就是方法:

import("importPath").then(() => {
// your code
});

hoặc

await import("importPath");

// your code

在这里查看更多https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

关于javascript - 如何在 Javascript/ReactJs/React Native 中动态导入模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59341858/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress