码迷,mamicode.com
首页 > 其他好文 > 详细

vue2.0学习笔记之生命周期

时间:2017-07-09 20:44:51      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:mount   logs   des   学习   eth   input   span   upd   style   

  • beforeCreate   组件实例刚刚被创建,属性都没有
  • created       实例已经创建完成,属性已经绑定
  • beforeMount    模板编译之前
  • mounted     模板编译之后,代替之前ready
  • beforeUpdate        组件更新之前
  • updated                 组件更新完毕
  • beforeDestroy       组件销毁前
  • destroyed              组件销毁后
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="box">
        <input type="button" value="更新数据" @click="update">
        <input type="button" value="销毁组件" @click="destroy">
        <br>
        {{msg}}
    </div>
</body>
</html>
<script src="vue.js"></script>
<script>
    new Vue({
        el:‘#box‘,
        data:{
            msg:‘welcome vue2.0‘
        },
        methods:{
            update(){
                this.msg=‘大家好‘;
            },
            destroy(){
                this.$destroy();
            }
        },
        beforeCreate(){
            console.log(‘组件实例刚刚被创建‘);
        },
        created(){
            console.log(‘实例已经创建完成‘);
        },
        beforeMount(){
            console.log(‘模板编译之前‘);
        },
        mounted(){
            console.log(‘模板编译完成‘);
        },
        beforeUpdate(){
            console.log(‘组件更新之前‘);
        },
        updated(){
            console.log(‘组件更新完毕‘);
        },
        beforeDestroy(){
            console.log(‘组件销毁之前‘);
        },
        destroyed(){
            console.log(‘组件销毁之后‘);
        }
    });
</script>

 

vue2.0学习笔记之生命周期

标签:mount   logs   des   学习   eth   input   span   upd   style   

原文地址:http://www.cnblogs.com/hcxy/p/7142634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!