首页 > 解决方案 > 如何在反应中添加我们的外部js文件

问题描述

谁能告诉我我们如何将外部 js 文件放入我们的 react 组件、index.html 或正文中。

尽可能提供代码

标签: reactjs

解决方案


在 React 代码中导入外部 js 文件。您只需要在index.html文件中写一行。

<script type="text/JavaScript" src="name of the file with extension"></script>

或者

<script type="text/JavaScript" src="url of the file on server"></script>

推荐阅读