Vue生命周期函数

<script>


        var app = new Vue({
                el: "#app",
                template: '<div>{{message}}</div>',
                data: {
                    message: 'hello world',
                },


                // vue实例基础初始化之后,就会触发
                beforeCreate: function() {
                    console.log('beforeCreate', 'this.message = ' + this.message);
                },

                // created在实例创建完成后被立即调用 挂载阶段还没开始 $el 属性目前尚不可用
                created: function() {
                    console.log('created', 'this.message= ' + this.message, 'this.$el =' + this.$el);
                },

                // 如果没有template模板,就会将el内的当成模板
                // 如果有template,就会用template里的东西
                // beforeMount:当和模板结合,在渲染页面之前的一瞬间,执行beforeMount函数(还没有渲染到页面上————用模板的情况下)
                beforeMount: function() {
                    console.log('beforeMount', 'this.$el =' + this.$el);
                },

                // 这时候hello World就会渲染在页面上了
                // mounted就会自动执行(已经渲染了)

                mounted: function() {
                    console.log("mounted", this.$el);
                },

                // 实例还没有销毁,在销毁的前一刻
                // 销毁实例:app.$destroy()
                beforeDestroy: function() {
                    console.log("beforeDestory", 'this.message= ' + this.message);
                },
                // 实例被销毁了
                destroyed: function() {
                    console.log("destoryed", 'this.message= ' + this.message);
                },
                // 数据发生改变,还没渲染之前
                beforeUpdate: function() {
                    console.log("beforeUpdate");
                    console.log(this.$el);
                },
                // 数据改变,渲染之后
                updated: function() {
                    console.log("updated");
                    console.log(this.$el);
                }



            })
            // app.message = 'hello'
            // app.$destroy();
    </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值