简体   繁体   English

如何在 ReactJS 的模块函数中调用另一个文件函数

[英]How to call another's file function in a module function on ReactJS

I want to call these function written on apiGet.js file:我想调用写在apiGet.js文件中的这些函数:

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

It's called on another module named brand.js file, this is the code:它在另一个名为brand.js文件的模块上调用,这是代码:

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

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

module.exports = sendGetRequest();

After executed, there is an error:执行后,报错:

Uncaught ReferenceError: apiGet is not defined

How to solve this?如何解决这个问题?

import { apiGet } from './actions';

Something like that should work.这样的事情应该有效。 The path will change depending on where actions is of course.当然,路径将根据操作的位置而变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ReactJS如何从同一文件上的另一个函数调用组件函数? - ReactJS how to call a component function from another function on the same file? 如何从reactJs中的另一个组件调用函数 - How to call function from another component in reactJs 如何在ReactJs中从另一个调用类函数 - How to call a class function from another in ReactJs 如何在javascript中从另一个文件调用模块导出函数 - How to call module export function from another file in javascript 如何在浏览器中为附加到 html 的模块设置正确的命名空间,以测试函数对该模块中另一个 function 的调用? - How to set correct namespace in jest for a module attached to html in browser for testing a function's call to another function in that module? 如何从 reactjs 中的另一个 function 呼叫一个 function? - How can I call a function from another function in reactjs? 如何从另一个模块调用函数 - How to call a function from another module 如何使用 ReactJS 使用 props 调用另一个组件中的函数? - How to call a function in another component with props using ReactJS? 如何从ReactJS中的onClick函数调用另一个组件 - How to call another component from onClick function in ReactJS 在另一个模块与 Jest 的依赖关系中断言 function 调用 - Assert a function call in another module's dependency with Jest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM