Vue 的生命週期 Posted on 2020-03-29 | In Vue 壹、 Vue 的生命週期 一、 Vue 的生命週期圖例及說明圖片來源:Lifecycle Diagram說明註解 By Pai 二、 vue instance 週期程式實做12345678910111213141516171819202122232425262728293031323334353637383940414243var vm = new Vue({ beforeCreate: function() { //vue instance 被 constructor 建立前 console.log('beforeCreate'); }, created: function() { //vue instance 被 constructor 建立後,在這裡完成 data binding console.log('created'); }, // =====執行 vm.$mount('#app'),讓實體物件綁定 DOM。===== // beforeMount: function() { //綁定 DOM 之前 console.log('beforeMount'); }, mounted: function() { //綁定 DOM 之後 console.log('mounted'); }, //===== 執行 vm.$forceUpdate(),來更新 DOM。 =====// beforeUpdate: function() { //資料更新,但尚未更新 DOM console.log('beforeUpdate'); }, updated: function() { //因資料更新,而更新 DOM console.log('updated'); }, //===== vm.$destroy(); 銷毀 instance =====// beforeDestroy: function() { //移除 vue instance 之前 console.log('beforeDestroy'); }, destroyed: function() { //移除 vue instance 之後 console.log('destroyed'); }}); 三、參考資料桑莫,夏天六角學院: 從 Vuejs 初探 Web Component 的世界