美文网首页
React生命周期函数

React生命周期函数

作者: 路人_Ding | 来源:发表于2019-01-09 16:28 被阅读0次

生命周期函数

  //组件挂载之前执行
  componentWillMount () {
    console.log("componentWillMount")
  }
  //组件挂载之后执行
  componentDidMount() {
    console.log("componentDidMount");
  }
  //组件更新之前会被执行
  shouldComponentUpdate() {
    console.log("shouldComponentUpdate")
    return true;
  }
 //组件跟新之前,它会自动执行,但是他在shouldComponentUpdate之后
  //如果shouldComponentUpdate返回true它才执行
  //如果shouldComponentUpdate返回false它就不执行
  componentWillUpdate() {
    console.log("componentWillUpdate")
  }
  //组件更新完成之后,才会被执行
  componentDidUpdate() {
    console.log("componentDidUpdate")
  }
  //一个组件要从父组件接受参数
  //如果这个组件第一次存在于父组件中,不会执行
  //如果这个组件之前已经存在于父组件,才会执行
  componentWillReceiveProps() {
    console.log("componentWillReceiveProps");
  }
    //当这个组件从页面中删除才会执行
    componentWillUnmount() {
        console.log("componentWillUnmount");
      }

生命周期函数性能优化

//当父组件的里的render被重新渲染后子组件需要判断要不要被从新渲染
    shouldComponentUpdate(nextProps,nextState) {
        if(nextProps.content !== this.props.content) {
            return true;
        }else{
            return false;
        }
    }

生命周期函数发送Ajax请求

首先先安装依赖
在项目的根目录下 :$ yarn add axios
improt axios from 'axios';
  componentDidMount() {
    axios.get('/app/todolist')
    .then(() => {alert('suscc')})
    .catch(() => { alert('erro')})
  }

相关文章

  • RN-生命周期函数(新)

    旧版生命周期函数 react 16.4 以后生命周期函数 http://projects.wojtekmaj.pl...

  • React 生命周期函数

    https://reactjs.org/docs/react-component.html React生命周期函数...

  • React的生命周期函数

    一、生命周期函数的定义 在某个时刻自动被调用的函数是生命周期函数 二、React中生命周期函数示意图 三、生命周期...

  • 04.React高级部分(中)

    React的生命周期函数 React生命周期函数的使用场景 这一小节,我们来做两个生命周期相关的常用操作1.如何避...

  • useState

    react-hooks 如果你熟悉 React class 的生命周期函数,你可以把 useEffect Hook...

  • 四:React 进阶三 (生命周期)

    react(一):组件的生命周期 生命周期函数 在组件运行的某个时刻,会被自动执行的一些函数。 React生命周期...

  • React快速上手5-react中的事件和生命周期函数

    这节中我们将主要介绍react应用中的事件和生命周期函数 React事件 在react中,我们不用addEvent...

  • react生命周期函数

    react 生命周期函数介绍[https://www.cnblogs.com/kdcg/p/9182393.htm...

  • 2020-09-11

    REACT生命周期 (JS胖老师课程 ) 生命周期函数指在某一个时刻组件会自动调用执行的函数 REACT生命周期的...

  • React 生命周期

    React 16.4 的生命周期图 早期React生命周期图 从图中,我们看到了一些变化 废弃的三个生命周期函数 ...

网友评论

      本文标题:React生命周期函数

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