【问题标题】:How to use let values from different js file to app.js in React如何在 React 中使用来自不同 js 文件的 let 值到 app.js
【发布时间】: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

标签: reactjs file include


【解决方案1】:

您可以使用以下命令进行命名导出:

export { strings };

然后你可以像这样在另一个文件中导入它:

import { strings } from './path/to/file.js'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-30
    • 2018-05-31
    • 1970-01-01
    • 2023-02-23
    • 2020-07-19
    • 1970-01-01
    相关资源
    最近更新 更多