react 组件

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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值