类组件的使用

export default class App extends Component{
    // 状态: 
    constructor(){
        super()//父级构造函数调用
        this.state={
               title:'zhaoxing',
               id:'1'
           }
     }
   // 渲染:
    render(){
       return (
            <div>
                <h1>hello {this.state.title}</h1>
                <h1>{this.state.id}</h1>
                <button onClick={()=>this.setState({id:this.state.id+1})}></button>
             </div>
        )
    }
}
posted @ 2022-11-17 19:21  Cherishe  阅读(22)  评论(0)    收藏  举报