美文网首页
Vue生命周期

Vue生命周期

作者: 茂茂爱吃鱼 | 来源:发表于2018-03-25 22:35 被阅读0次
    <div id="app">
      {{ message }}
    </div>
    var app = new Vue({
      el: '#app',
      data: {
        message: 'Hello Vue!'
      },
      beforeCreate: function() {
        console.log('--------------beforeCreate----------------');
        console.log(this.$el);
        console.log('data: ' + this.$data);
        console.log('message: ' +  this.message);
      },
      created: function() {
        console.log('--------------created----------------');
        console.log(this.$el);
        console.log('data: ' + JSON.stringify(this.$data));
        console.log('message: ' +  this.message);
      },
      beforeMount: function() {
        console.log('--------------beforeMount-----------------');
        console.log(this.$el);
        console.log('data: ' + JSON.stringify(this.$data));
        console.log('message: ' +  this.message);
      },
      mounted: function() {
        console.log('--------------mounted---------------');
        console.log(this.$el);
        console.log('data: ' + JSON.stringify(this.$data));
        console.log('message: ' +  this.message);
      },
      beforeUpdate: function() {
        console.log('--------------beforeUpdate----------------');
        console.log(this.$el);
        console.log('data: ' + JSON.stringify(this.$data));
        console.log('message: ' +  this.message);
      },
      updated: function() {
        console.log('--------------updated---------------');
        console.log(this.$el);
        console.log('data: ' + JSON.stringify(this.$data));
        console.log('message: ' +  this.message);
      },
      beforeDestroy: function() {
        console.log('--------------beforeDestroy---------------');
        console.log(this.$el);
        console.log('data: ' + JSON.stringify(this.$data));
        console.log('message: ' +  this.message);
      },
      destroyed: function() {
        console.log('--------------destroyed-------------');
        console.log(this.$el);
        console.log('data: ' + JSON.stringify(this.$data));
        console.log('message: ' +  this.message);
      }
    })
    
    demo.png
    update.png
    destroy.png
    lifecycle.png
    beforeCreate created beforeMount mounted beforeUpdate updated beforeDestroy destroyed
    data observer & event/watcher 事件配置之前 data observer & event/watcher 完成,$el不可见 $el可见,挂载之前 挂载完成 数据更新,DOM未渲染 DOM已渲染 实例销毁前,实例仍可用 解绑完成

    相关文章

      网友评论

          本文标题:Vue生命周期

          本文链接:https://www.haomeiwen.com/subject/ffmhcftx.html