为 ReactDOM.render 在 html 中的何处放置代码行? [英] Where to place line of code in html for ReactDOM.render?

查看:37
本文介绍了为 ReactDOM.render 在 html 中的何处放置代码行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,保存格式为 .html (index.html).

I have the following code which is in a saved format of .html (index.html).

我现在正在学习 React,当我在浏览器中执行这个 html 文件时,没有任何反应.

I am learning React right now and when I execute this html file in the browser, nothing happens.

我想知道这两行代码应该放在哪里或如何调用它们(执行渲染).

I am wondering where the two lines of code are suppose to go or how to call them (execute the rendering).

如果我使用的是 mac,我在哪里可以找到 ./lib 中的文件?

Where would I find the files in ./lib if I am using a mac?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Introduction | Learning React</title>
    <link rel="stylesheet" href="lib/style.css" />
  </head>
  <body>
    <section id="entry-point"></section>

    <!-- Wifi might be spotty, so we've downloaded these to `./lib` -->
    <script src="lib/react.js"></script>
    <script src="lib/react-dom.js"></script>

    <script type="text/javascript">
      // Intentionally blank. Your walk-through code will go here
      var hello = React.createElement('p', null, 'Hello, World!');

      // Checkout what this does by opening your HTML file in the browser
      ReactDOM.render(hello, document.getElementById('entry-point'));
    </script>
  </body>
</html>

推荐答案

如果您不想使用数据包管理器,您可以将 React 与 CDN 结合.

If you don't want to use packet managers you can include React with CDNs.

用于开发:

<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>

用于生产(缩小):

<script src="https://unpkg.com/react@15/dist/react.min.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script>

这篇关于为 ReactDOM.render 在 html 中的何处放置代码行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆