知识点
1:使用jsx的方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>react</title>
</head>
<body>
<div id="test"></div>
<script type="text/javascript" src="../js/react.development.js"></script>
<script type="text/javascript" src="../js/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script type="text/babel">
const VDOM =(
<h1>
<span>hello,react</span>
</h1>
)
ReactDOM.render(VDOM,document.getElementById('test'))
</script>
</body>
</html>
2:使用js的方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>react</title>
</head>
<body>
<div id="test"></div>
<script src="../js/react.development.js"></script>
<script src="../js/react-dom.development.js"></script>
<script>
const VDOM = React.createElement('h1',{
id:'test'},React.createElement('span',{
},'hello,react'));
ReactDOM.render(VDOM,document.getElementById('test'));
</script>
</body>
</html>
3:从上面的例子可以看出,如果dom结构比较多,使用React.createElement非常的麻烦,使用jsx语法更加的方便。其实是babel帮助我们把jsx翻译成了js的这种写法。
React.createElement(标签名,标签属性,标签内容)