3-类组件

匿名 (未验证) 提交于 2019-12-02 23:42:01

React.Componentrender()JSX

class Clock extends React.Component {    // render函数表示渲染,每次重新渲染都要调用该函数    render(){      return (        <div>          <h2>Clock, {this.props.name}</h2>        </div>      );    }  }

state

UIstatesuper(props)

class Clock extends React.Component {      constructor(props){    //props形参在构造器中,和函数组件不一样      super(props);          this.state = {              now:new Date().toLocaleString()         }    }  }

state

1state

this.setState()

2State

setStatestate

componentDidMount

setState

componentWillUnmount

'onXxx'thisrender()

this

es6thisundefinedthisthis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!