生命週期(鉤子函數)
1.0
var vm = new Vue({
el:'#app',//沒有el 是沒法進行編譯的
data:{
msg:'zf'
},
init(){
alert('初始化')
},
created(){
alert('初始化完成')
},
beforeCompile(){
alert('編譯前')
},
compiled(){
alert('編譯後')
},
ready(){
//首次加載獲取以前 在ready方法後獲取數據 (官方推薦 )
alert('準備好了')
},
beforeDestroy(){
alert('銷燬前')
},
destroyed(){
alert('銷燬後')
}
})
vm.$destroy(); // 強制讓實例小會,可是編譯後的數據不會銷燬
console.log(vm)
vm.$mount('#app')//手動掛載
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
2.0
var vm = new Vue({
el:'#app',//沒有el 是沒法進行編譯的
data:{
msg:'zf'
},
beforeCreate(){
alert('初始化以前')
},
created(){
alert('初始化完成')
},
beforeMount(){
alert('掛載前')
},
mounted(){
alert('掛載後')
},
beforeUpdate(){
//首次加載獲取以前 在ready方法後獲取數據 (官方推薦 )
alert('修改前')
},
updated(){
alert('修改後')
},
beforeDestroy(){
alert('銷燬前')
},
destroyed(){
alert('銷燬後')
}
})
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)