vue(4)

vue生命周期

钩子函数:

1、created         -----        实例已经创建的时候执行,也就是new Vue成功了之后执行

2、beforeCompile      -----  实例创建完了, 编译之前

3、compiled                 -----        编译之后

4、ready                      -----        插入到文档中

5、beforeDestroy         -----        销毁之前

6、destroyed                -----        销毁之后

     window.onload=function(){
                var vm= new Vue({
                    el:'#box',
                    data:{
                        msg:'Hello word'
                    },
                    created:function(){
                        alert('实例已经创建')
                    },
                    beforeCompile:function(){
                        alert('编译之前')
                    },
                    compiled:function(){
                        alert('编译之后')
                    },
                    ready:function(){
                        alert('插入到文档中')
                    },
                    beforeDestroy:function(){
                        alert('销毁之前 ')
                    },
                    destroyed:function(){
                        alert('销毁之后')
                    }
                    
                });
                 document.onclick=function(){
                    vm.$destroy()      //让销毁管用
                };
           };       
原文地址:https://www.cnblogs.com/sun927/p/7147408.html