【问题标题】:How to call another's file function in a module function on ReactJS如何在 ReactJS 的模块函数中调用另一个文件函数
【发布时间】:2020-10-16 08:25:32
【问题描述】:

我想调用写在apiGet.js文件中的这些函数:

export let apiGet = () => {
    return 'File One';
}

在另一个名为 brand.js 文件的模块上调用,代码如下:

require("../actions/apiGet.js");

const sendGetRequest = () => {
    console.log(apiGet());
};

module.exports = sendGetRequest();

执行后出现错误:

Uncaught ReferenceError: apiGet is not defined

如何解决?

【问题讨论】:

  • const { apiGet } = require(...);?尽管您似乎在混合模块系统。
  • 它有效,你节省了我的时间。非常感谢。
  • 现在我意识到术语 { apiGet } 表示 apiGet.js 中的函数名称。如果我们在文件 apiGet.js 中有另一个函数,它应该被称为 { apiGet, anotherFunction }。

标签: javascript node.js reactjs


【解决方案1】:
import { apiGet } from './actions';

类似的东西应该可以。当然,路径会根据动作的位置而改变。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    相关资源
    最近更新 更多