react-native生命周期

//初始化
    constructor(props) {
        super(props);
        console.log('---------constructor--------')
    }
    //组件将要加载,整个生命周期只执行一次,在render方法之前执行
    componentWillMount() {
        console.log('---------componentWillMount--------')

    }
    //组件已经加载,在render方法之后执行,整个生命周期只执行一次
    componentDidMount() {
        console.log('---------componentDidMount--------')

    }
    //在组件接收到其父组件传递的props的时候执行,参数为父组件传递的props。在组件的整个生命周期可以多次执行
    componentWillReceiveProps(nextProps) {
        console.log('---------componentWillReceiveProps--------')
        this.setState({
            //key : value
        });
    }
    //在componentWillReceiveProps(nextProps)执行之后立刻执行;或者在state更改之后立刻执行
    shouldComponentUpdate(nextProps, nextState) {
        console.log('---------shouldComponentUpdate--------')
        return true;
    }
    //在shouldComponentUpdate(nextProps, nextState)函数执行完毕之后立刻调用,该方法包含两个参数
    componentWillUpdate(nextProps, nextState) {
        console.log('---------componentWillUpdate--------')

    }

    //在render()方法执行之后立刻调用。该方法包含两个参数,分别是props和state
    componentDidUpdate(preProps, preState) {
        console.log('---------componentDidUpdate--------')

    }

    //render方法用于渲染组件。在初始化阶段和运行期阶段都会执行。
    render() {
        console.log('---------render--------')
        return (
            <Tex></Text>
        );
    }

    //在组件由虚拟DOM卸载的时候调用
    componentWillUnmount() {
        console.log('---------componentWillUnmount--------')

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值