簡體   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