react学习笔记(一)

import React from 'react';
import ReactDOM from 'react-dom';
//es6语法
//style内联样式不能用html那种方式,需要用对象写法如style={{"color":'red'}} ,class要写成className,因为class在es6中是关键字
//{}js表达式
class Hello extends  React.Component{
    constructor(props) {
        super(props);
        this.state = {  opacity:1,
            fontSize:'12px'  //这种类型要写成驼峰式写法
            };
    }

    render(){


        return <div style={{opacity:this.state.opacity,fontSize:this.state.fontSize}} className="dd"> Hello {this.props.name}</div>
    }
}
ReactDOM.render(
    <Hello name = "react"/>,
    document.getElementById('app')
);

猜你喜欢

转载自blog.csdn.net/yilanyoumeng3/article/details/79540804