生命周期函数

 <!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="vue.js"></script>
        
    </head>
    <body>
        <div id="app">
            
        </div>
        <script>
            var vm = new Vue({
                el:"#app",
                template:"<div>{{test}}</div>",
                data:{
                    test:'hello'
                },
                //生命周期函数就是vue实例在某一个时间点会自动执行的函数
                beforeCreate:function(){
                    console.log("基础初始化时调用函数beforeCreate");
                },//基础初始化时调用函数
                created:function(){
                    console.log("创建完成后调用created")
                },//创建完成后调用
                beforeMount:function(){
                    console.log("模板和数据结合的时候执行beforeMount");
                    console.log(this.$el);
                },//模板和数据结合的时候执行
                mounted:function(){
                    console.log("页面挂载之后执行mounted");
                    console.log(this.$el);
                },//页面挂载之后执行,页面已经渲染完毕
                beforeDestroy:function(){
                    console.log("组件即将销毁时执行beforeDestroy");
                },//组件即将销毁时执行
                destroyed:function(){
                    console.log("已经销毁时执行destroyed")
                },//已经销毁时执行
                beforeUpdate:function(){
                    console.log("数据改变,还没有渲染时执行beforeUpdate")
                },//数据改变,还没有渲染时执行
                updated:function(){
                    console.log("渲染完成时执行updated")
                }//渲染完成时执行
            })
        </script>
    </body>
</html>

生命周期函数单独放在函数里就行,不需要放在methods中,
转载于猿2048:➭《生命周期函数》

评论

暂无评论