React之HelloWorld

第一个程序HelloWorld

  1. 先安装react,react-dom,babel
    在0.14版本发布后,react拆分为react,react-dom,同时弃用了react-tools 及 JSXTransformer.js,推荐使用babel(javascript编译器)来编译JSX。
mkdir helloreact
cd helloreact
npm init --yes
npm install react react-dom babel-standalone --save
  1. 新建hello.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Hello React</title>
    <script src="./node_modules/react/dist/react.js"></script>
    <script src="./node_modules/react-dom/dist/react-dom.js"></script>
    <script src="./node_modules/babel-standalone/babel.js"></script>
</head>
<body>
    <div id="app"></div>

    <script type="text/babel">
        ReactDOM.render(
            <h1>Hello World!</h1>,
            document.getElementById('app')
        );
    </script>
</body>
</html>
  1. 在浏览器中运行hello.html
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容