第一个程序HelloWorld
- 先安装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
- 新建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>
- 在浏览器中运行hello.html
image.png
网友评论