import React from 'react'

class Demo extends React.Component{
  constructor(props){
    super(props)
    this.state={count:1}
    this.handleClick=this.handleClick.bind(this)
  }
  handleClick(){
    this.setState({count:this.state.count+1})
  }
  shouldComponentUpdate(){
    if(this.state.count%5==0){

      return true
    }
    return false
  }
  render(){
    return (
      <div>
        {this.state.count}<br />
        <button onClick={this.handleClick}>点击</button>
      </div>

    )
  }
}
export default Demo

只有当count等于5时,视图上才会更新数据

相关文章:

  • 2022-01-01
  • 2021-10-10
  • 2022-12-23
  • 2021-09-11
  • 2021-08-07
  • 2021-04-12
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2021-12-26
  • 2021-10-10
  • 2021-05-22
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案