简体   繁体   English

如何将javascript文件从公用文件夹导入SRC文件夹并使用该文件的功能

[英]How to import javascript file from public folder to SRC folder and use the function of that file

I am using topol.io email builder in ReactJS. 我在ReactJS中使用topol.io电子邮件构建器。 i tried putting there plugin script inside src folder. 我试着把插件脚本放在src文件夹中。 But it was not working. 但它没有用。 Then i tried to put that file in public folder then it worked. 然后我试图将该文件放在公共文件夹然后它工作。 Now i want to use the function of that JavaScript file in reactjs app. 现在我想在reactjs应用程序中使用该JavaScript文件的功能。

How can i use that file's function. 我该如何使用该文件的功能。 Or is there any way i can use that plugin folder inside my src directory. 或者有什么办法可以在我的src目录中使用该插件文件夹。

 componentDidMount() {
    const script = document.createElement("script");

    script.src = "/static/topol.js";
    script.async = false;
    document.body.appendChild(script);
  }

this is how i am using it now. 这就是我现在使用它的方式。

You need to import your file. 您需要import您的文件。 This will include it in the bundle, and you'll be able to use the functions defined in it. 这将包含在捆绑包中,您将能够使用其中定义的功能。

Be aware that your ability to use a function defined in this file will depend on the way the function is exposed and declared. 请注意,您使用此文件中定义的函数的能力取决于函数的公开和声明方式。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM