Vue生命周期

<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不可見(jiàn) $el可見(jiàn),掛載之前 掛載完成 數(shù)據(jù)更新,DOM未渲染 DOM已渲染 實(shí)例銷(xiāo)毀前,實(shí)例仍可用 解綁完成
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 寫(xiě)在最前面 一直都想在更新博客但是都因?yàn)閼蟹艞壛?看了無(wú)問(wèn)西東之后找了點(diǎn)正能量,更新起來(lái) vue從出生到現(xiàn)在,從一...
    StevenTang閱讀 1,941評(píng)論 2 9
  • 這是官網(wǎng)上一個(gè)最簡(jiǎn)單的例子 接下來(lái)我通過(guò)在chrome中一步步運(yùn)行代碼來(lái)理清其內(nèi)部邏輯。首先當(dāng)然是調(diào)用構(gòu)造函數(shù) 然...
    丨ouo丨閱讀 724評(píng)論 0 1
  • beforeCreate created beforeMount mounted beforeUpdate upd...
    R_X閱讀 402評(píng)論 0 0
  • vue的生命周期如圖所示: 它可以總共分為8個(gè)階段:beforeCreate(創(chuàng)建前),created(創(chuàng)建后),...
    黃鶴你不是人閱讀 1,279評(píng)論 0 0
  • 原理: 在opencv改變圖像的對(duì)比度和亮度本質(zhì)是對(duì)像素點(diǎn)的操作,一個(gè)像素映射到另一個(gè)像素,用數(shù)學(xué)表示就是f(x,...
    魚(yú)小莘閱讀 1,177評(píng)論 0 2

友情鏈接更多精彩內(nèi)容