美文网首页
(React)生命周期方法

(React)生命周期方法

作者: fanren | 来源:发表于2021-04-12 10:05 被阅读0次
class App extends Component {

  constructor(props) {
    super(props)
    console.log('constructor')
  }

  componentDidMount() {
    console.log('componentDidMount')
  }

  componentWillUnmount() {
    console.log('componentWillUnmount')
  }

  respondsToClick(title, e) {
    console.log(this)
    console.log(title)
    console.log(e)
  }
  render() {
    return (
      <div className="App">
        <div>aaaa</div>
        <a onClick={(e) => this.respondsToClick('addd', e)}>点击增加</a>
      </div>
    );
  }
}
export default App;

生命周期方法详解

  • constructor
    组件的初始化方法,组件初始化的时候会调用;
    该方法的参数是props,是父组件传递的所有的属性值对象;
  • componentWillMount
    组件在渲染前调用,在客户端也在服务端。
  • componentDidMount
    在组件完成渲染后调用;
  • componentWillReceiveProps
    在组件接收到一个新的 prop (更新后)时被调用
  • shouldComponentUpdate
    返回一个布尔值。在组件接收到新的props或者state时被调用
  • componentWillUpdate
    在组件接收到新的props或者state,但还没有渲染时被调用
  • componentDidUpdate
    在组件完成更新后立即调用。
  • componentWillUnmount
    在组件从 DOM 中移除之前立刻被调用。

相关文章

  • React v16 生命周期

    React 16 生命周期 React 16.3 新增的生命周期方法 逐渐废弃的生命周期方法: 一般将生命周期分成...

  • React 生命周期

    React 生命周期方法 我们接触较多的应该是 render()方法,其实这也是React的生命周期方法之一。还有...

  • React Native 入门(三):

    componentDidMount()方法 componentDidMount是React组件的一个生命周期方法,...

  • React入门--组件生命周期

    React组件有自己的生命周期方法,React将组件从挂载(Mounting)-->更新(Updating)-->...

  • react事务

    react事务机制,混合setState 1.react的事务,几乎贯穿了react所有提供调用的方法。生命周期,...

  • React基础

    学习记录 常用的生命周期方法 生命周期图谱https://projects.wojtekmaj.pl/react-...

  • React概念图

    React概念图 React组件生命周期概念图 参考文档:React入门教程 组件生命周期React:组件生命周期...

  • React基础篇之组件的生命周期

    引出生命周期 react生命周期(旧) react生命周期(新) getSnapshotBeforeUpdate的...

  • React生命周期

    React生命周期 每个组件都有几个“生命周期方法”,您可以在此过程中的特定时间覆盖运行代码。前缀是will的方法...

  • React入门(二)

    三、React组件 React 组件基本上是由组件的构建方式、组件内的状态属性与生命周期方法组成 React.cr...

网友评论

      本文标题:(React)生命周期方法

      本文链接:https://www.haomeiwen.com/subject/rhqekltx.html