(四)Vue的生命周期

本节知识点

  • Vue里面一共有10个声明

代码概括

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0">
    <title>Title</title>
    <script src="js/vue.js"></script>
</head>
<body>
  <div id="app">
       <div>{{message}}</div>
      <button @click="add">加分</button>
  </div>
</body>
<script>
    var app = new Vue({
        el:"#app",
        data:{
            message:1
        },
        methods:{
            add:function(){
                this.message++;
            }
        },
        //下面是10个钩子函数
        beforeCreate:function(){
            console.log("1--beforecreate 初始化之后")
        },
        created:function(){
            console.log("2--created创建之后")
        },
        beforeMount:function(){
            console.log("3--beforeMount挂载之前")
        },
        mounted:function(){
            console.log("4--mounted 挂载之后")
        },
        beforeUpdate:function(){
            console.log("5--update 更新之前");
        },
        updated:function(){
            console.log("6--更新之后");
        },
        activated:function(){
            console.log("7--组件被激活的时候使用");
        },
        deactivated:function(){
            console.log("8--组件被移除的时候使用")
        },
        beforeDestroy:function(){
            console.log("9--销毁前使用")
        },
        destroyed:function(){
            console.log("10--销毁后使用")
        }

    })
</script>
</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 见字如面。好怀念那个见字如面的年代。发出去一封信,默默的在心里算着他有没有收到,悄悄地想着对方看信时的表情,再满怀...
    叫我莎拉阅读 350评论 0 0
  • 97年 天蝎座 没有二十岁但感觉时间过的超快看着别人的生活感觉以后自己的人生难道也会是这样在家洗衣做饭照顾...
    羊羊小眼睛阅读 242评论 0 0
  • 北京北行,短短3个小时,从已满眼花繁叶茂绿意盎然的深春,驶回仿若冬末的萧瑟。 由于海拔原因,草原天...
    鸥叔阅读 487评论 2 6
  • 提剑跨骑挥尾雨,白骨如山鸟惊飞,尘世如潮人如水,只叹江湖几人回。 有江有湖,有人有家。 人心就是...
    高能磷酸阅读 185评论 0 0