1.注意: 组件 变量名 首字母 必须大写
<div id="example"></div>
<script type="text/babel">
var A = React.createClass({
render: function(){
return <h1>hello ! {this.props.name}</h1>;
}
});
ReactDOM.render(
<A name="DS"/>,
document.getElementById('example')
)
</script>
2. 组件类只能包含一个顶层标签,否则也会报错。
return : 后面 只能写一个标签。
3. 组件类: className, htmlFor
添加组件属性,有一个地方需要注意,就是 class
属性需要写成 className
,for
属性需要写成 htmlFor
,这是因为 class
和 for
是 JavaScript 的保留字。
<body>
<h1>属性class,for不能再出现。class --> className; for ---> htmlFor</h1>
<div id="example"></div>
<script type="text/babel">
var Hello = React.createClass({
render : function(){
return <h1>hello,color: { this.props.color };{ this.props.className };{ this.props.htmlFor }</h1>;
}
})
ReactDOM.render(
<Hello color="red" className="class名" htmlFor="forname"/>,
document.getElementById('example')
)
</script>
</body>