美文网首页实用前端前端uni-app
uni-app 生命周期函数执行顺序

uni-app 生命周期函数执行顺序

作者: 悠哉悠哉_8c2a | 来源:发表于2019-07-16 11:31 被阅读0次
<template>
    <view ref="ref" class="test-container">
        <text>{{message}}</text>
        <button @click="addMsg">点击</button>
    </view>
</template>

<script>
    
    import {
        mapState,
        mapMutations
    } from 'vuex';
    var key = 0;
    export default {

        data() {
            return {
                message: 1
            }
        },

        computed: {
            
        },

        methods: {

            addMsg() {
                this.message++
            }

        },
        
        beforeCreate() {
            console.group('beforeCreate 组件创建之前状态===============》');
            console.log("%c%s", "color:red" , "el     : " + this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message)
        },
        
        onLoad() {
            console.group('onLoad 状态===============》');
            console.log("%c%s", "color:red" , "el     : " + this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message)
        },
        
        onShow() {
            console.group('onShow 状态===============》');
            console.log("%c%s", "color:red" , "el     : " + this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message)
        },
        
        onReady() {
            console.group('onReady 状态===============》');
            console.log("%c%s", "color:red" , "el     : " + this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message)
        },
        
        onUnload() {
            console.group('onUnload 状态===============》');
            console.log("%c%s", "color:red" , "el     : " + this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message)
        },
        
        
        created() {
            console.group('created 组件创建完毕状态===============》');
            console.log("%c%s", "color:red","el     : " + this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message);
        },
        
        beforeMount() {
            console.group('beforeMount 组件挂载之前状态===============》');
            console.log("%c%s", "color:red","el     : " + (this.$el));
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message);
        },
        
        mounted() {
            console.group('mounted 组件挂载完毕状态===============》');
            console.log("%c%s", "color:red","el     : " + this.$el);
            console.log(this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message);
        },
        
        beforeUpdate() {
            console.group('beforeUpdate 组件更新之前状态===============》');
            console.log("%c%s", "color:red","el     : " + this.$el);
            console.log(this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message);
        },
        
        updated() {
            console.group('updated 组件更新完毕状态===============》');
            console.log("%c%s", "color:red","el     : " + this.$el);
            console.log(this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message);
        },
        
        beforeDestroy() {
            console.group('beforeDestroy 组件销毁之前状态===============》');
            console.log("%c%s", "color:red","el     : " + this.$el);
            console.log(this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message);
        },
        
        destroyed() {
            console.group('destroyed 组件销毁完毕状态===============》');
            console.log("%c%s", "color:red","el     : " + this.$el);
            console.log(this.$el);
            console.log("%c%s", "color:red","data   : " + this.$data);
            console.log("%c%s", "color:red","message: " + this.message)
        }
        
    }
</script>

<style lang="scss">
    .test-container {
        width: 100%;
        height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        box-sizing: border-box;
        padding: 0upx 40upx;
        button {
            margin-top: 100upx;
        }
    }
</style>
屏幕快照 2019-07-16 上午11.11.14.png

当点击按钮时

屏幕快照 2019-07-16 上午11.24.36副本.png

总结

Page页面生命周期函数执行顺序

beforeCreate => onLoad => onShow => created => beforeMount => onReady => mounted

刷新数据后

beforeUpdate => updated

相关文章

  • React生命周期函数详解+例子

    周期函数定义引用自官方(以下函数的顺序顺序即生命周期函数的执行顺序) componentWillMount 在渲染...

  • uni-app 生命周期函数执行顺序

    当点击按钮时 总结 Page页面生命周期函数执行顺序 beforeCreate => onLoad => onSh...

  • 生命周期函数

    应用生命周期 uni-app 支持如下应用生命周期函数: onLaunch:当uni-app 初始化完成时触发(全...

  • uni-app 页面生命周期

    uni-app 页面生命周期 页面生命周期 uni-app 支持如下页面生命周期函数: onLoad 监听页面加载...

  • uni-app系列(三)

    文章内容:uni-app生命周期和模版语法 uni-app 支持如下页面生命周期函数:onLoad 监听页面加载,...

  • Vue的生命周期函数

    创建期间的生命周期函数: beforeCreate() 在beforeCreate() 生命周期函数执行的时候,...

  • Vue2.0 探索之路——生命周期和钩子函数的一些理解

    vue生命周期函数 生命周期探究 对于执行顺序和什么时候执行,看上面两个图基本有个了解了。下面我们将结合代码去看看...

  • Activity 生命周期函数执行顺序

    第一步:使用AndroidStudio 创建一个空项目 覆盖生命周期函数 7个 1 debug 启动调试App 启...

  • Vue学习笔记(12)-生命周期函数

    生命周期函数 生命周期函数代表的是Vue实例,或者是Vue组件,在网页中各个生命阶段所执行的函数。生命周期函数可以...

  • Vue 生命周期

    生命周期函数 生命周期函数就是 Vue 实例在某一个时间点会自动执行的函数 简单来说就是,钩子(生命周期函数)就好...

网友评论

    本文标题:uni-app 生命周期函数执行顺序

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