vue的生命周期

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <meta http-equiv="X-UA-Compatible" content="ie=edge">

  <title>vue生命周期学习</title>

  <script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>

</head>

<body>

  <div id="app">

    <h1>{{message}}</h1>

  </div>

</body>

<script>

  var vm = new Vue({

    el: '#app',

    data: {

      message: 'Vue的生命周期'

    },

    beforeCreate: function() {

      console.group('------beforeCreate创建前状态------');

      console.log("%c%s", "color:red" , "el    : " + this.$el); //undefined

      console.log("%c%s", "color:red","data  : " + this.$data); //undefined

      console.log("%c%s", "color:red","message: " + this.message)

    },

    created: function() {

      console.group('------created创建完毕状态------');

      console.log("%c%s", "color:red","el    : " + this.$el); //undefined

      console.log("%c%s", "color:red","data  : " + this.$data); //已被初始化

      console.log("%c%s", "color:red","message: " + this.message); //已被初始化

    },

    beforeMount: function() {

      console.group('------beforeMount挂载前状态------');

      console.log("%c%s", "color:red","el    : " + (this.$el)); //已被初始化

      console.log(this.$el);

      console.log("%c%s", "color:red","data  : " + this.$data); //已被初始化 

      console.log("%c%s", "color:red","message: " + this.message); //已被初始化 

    },

    mounted: function() {

      console.group('------mounted 挂载结束状态------');

      console.log("%c%s", "color:red","el    : " + this.$el); //已被初始化

      console.log(this.$el);   

      console.log("%c%s", "color:red","data  : " + this.$data); //已被初始化

      console.log("%c%s", "color:red","message: " + this.message); //已被初始化

    },

    beforeUpdate: function () {

      console.group('beforeUpdate 更新前状态===============》');

      console.log("%c%s", "color:red","el    : " + this.$el);

      console.log(this.$el); 

      console.log("%c%s", "color:red","data  : " + this.$data);

      console.log("%c%s", "color:red","message: " + this.message);

    },

    updated: function () {

      console.group('updated 更新完成状态===============》');

      console.log("%c%s", "color:red","el    : " + this.$el);

      console.log(this.$el);

      console.log("%c%s", "color:red","data  : " + this.$data);

      console.log("%c%s", "color:red","message: " + this.message);

    },

    beforeDestroy: function () {

      console.group('beforeDestroy 销毁前状态===============》');

      console.log("%c%s", "color:red","el    : " + this.$el);

      console.log(this.$el);   

      console.log("%c%s", "color:red","data  : " + this.$data);

      console.log("%c%s", "color:red","message: " + this.message);

    },

    destroyed: function () {

      console.group('destroyed 销毁完成状态===============》');

      console.log("%c%s", "color:red","el    : " + this.$el);

      console.log(this.$el); 

      console.log("%c%s", "color:red","data  : " + this.$data);

      console.log("%c%s", "color:red","message: " + this.message)

    }

  })

</script>

</html>

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

推荐阅读更多精彩内容

  • 在使用vue一个多礼拜后,感觉现在还停留在初级阶段,虽然知道怎么和后端做数据交互,但是对于mounted这个挂载还...
    情话_2ee5阅读 3,576评论 0 0
  • vue生命周期简介 图片发自简书App 咱们从上图可以很明显的看出现在vue2.0都包括了哪些生命周期的函数了。 ...
    F_imok阅读 3,573评论 0 1
  • vue生命周期简介 咱们从上图可以很明显的看出现在vue2.0都包括了哪些生命周期的函数了。 生命周期探究 对于执...
    余生LHX阅读 3,938评论 0 3
  • {{ message }} var app = new Vue({ el: '#app', data...
    汪槑槑2017阅读 3,701评论 0 0
  • 晨光微醺楼宇间, 红日初现霞满天, 前路渐明步渐宽, 春枝福葉共风展。
    陈光彬阅读 669评论 2 1