【发布时间】:2019-08-18 02:13:36
【问题描述】:
我正在使用 react-localization 并为语言变量定义代码 在 App.js 中
import LocalizedStrings from "react-localization";
let strings = new LocalizedStrings({
en: {
how: "how are you"
},
it: {
how: "Come vuoi il tuo uovo oggi?"
}
});
export strings;
我们可以在 App.js 中将它用作 {strings.how} 但我的问题是,当语言值大幅增加时,我们可以将它移动到不同的 lang.js 文件中并在 app.js 中调用它。
如何从不同的文件导入和使用“let strings”?
【问题讨论】:
-
您可以使用
export { strings };导出它,然后使用import { strings } from './path/to/file.js'将其导入另一个文件 -
是的,这行得通。
-
我的回答对你有用吗?如果是这种情况,请考虑 accepting it。