繁体   English   中英

我该如何使用<script> tags inside a JSX file?

[英]How can I use <script> tags inside a JSX file?

我只是将一些 HTML 转换为 JSX,但在 HTML 文件中有几个脚本标签。 这是下面的代码:


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/web3.min.js"></script>
    <script src="js/truffle-contract.js"></script>
    <script src="js/app.js"></script>
  </body>
</html>

我想知道如何在 JSX 文件中使用它们,我已经把它变成了一个组件。 我要导入它们吗?

您应该像我在下面展示的那样在 index.html 中添加脚本。 此外,您应该避免在此处使用带有 React 检查的 jquery。

+-- React root dir
    +-- public
        +-- index.html
     

索引.html

<body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
    --> add scripts here
</body>

此外,您可以导入 Bootstrap 阅读 此内容

暂无
暂无

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

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