<!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">
<style>
.bg {
background: pink;
}
</style>
<title>helloReact</title>
</head>
<body>
<div id="test"></div>
<script src="../js/react.development.js"></script>
<script src="../js/react-dom.development.js"></script>
<script src="../js/babel.min.js"></script>
<script type="text/babel">
const classId = 'box'
const text = 'hello world!!!'
const VDOM = (
<div>
<h1 id={classId} className="bg" style={{color: '#fff', fontSize: '40px', textAlign: 'center'}}>
<span>
{text}
</span>
</h1>
<input/>
</div>
)
ReactDOM.render(VDOM, document.getElementById('test'))
/*
jsx语法规则
1、定义虚拟dom时,不要写引号
2、标签中混入JS表达式时要用{}
3、样式的类名指定不要用class,要用clasName
4、内联样式要用style={{key: value}}的形式去写
5、只有一个根标签
6、标签必须闭合
7、标签首字母
①若小写字母开头,则将该标签转为html中同名元素,若html中无该标签对应的同名元素,则报错
②若大写字母开头,react就会去渲染对应的组件,若组件没有定义,则报错
*/
</script>
</body>
</html>
jsx语法规则
最新推荐文章于 2024-06-16 08:27:28 发布