张蕾的技术博客Web前端之路让前端飞

react基础知识快速学习

2017-06-04  本文已影响245人  cd72c1240b33

项目构建

跑通项目

jsx语法

render(){
    const name="圆梦源123";
    const styles={
        fontSize:'30px',
        color:'red'
    };
    return(
        <div style={styles}>
            {/*这是jsx中的注释*/}
            <h1>你好,{name}!</h1>
        </div>
    )
}

react虚拟DOM

对react组件添加样式

react中的属性props

var MyComponent=function(props){
    var state={

    }
    return "v dom"
}

refs引用DOM元素:range举例

update=(e)=>{
    console.log(findDOMNode(this.refs.one).value)
    this.setState({
        name:e.target.value
    })
}

子组件children属性

react生命周期图

react-router内容介绍,我们使用3.0.5版本

<Redirect from="/about" to="/about/react"></Redirect>

Confirm Navigation

//组件中
componentDidMount(){
    this.context.router.setRouteLeaveHook(this.props.route,this.leaveHook)
}
leaveHook(nextLocation){
    console.log(nextLocation)
    return 'you want leave?'
}
//contextTypes的设置
Contact.contextTypes={
    router:propTypes.object
};

上一篇 下一篇

猜你喜欢

热点阅读