vue-lifecycle.png
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="../assets/js/vue.js"></script>
<title>構(gòu)造器的聲明周期</title>
</head>
<body>
<h1>構(gòu)造器的聲明周期</h1>
<hr>
<div id="app">
{{message}}
<p><button @click="jia">加分</button></p>
</div>
<button onclick="app.$destroy()">銷毀</button>
<script type="text/javascript">
var app=new Vue({
el:'#app',
data:{
message:1
},
methods:{
jia:function(){
this.message ++;
}
},
beforeCreate:function(){
console.log('1-beforeCreate 初始化之后');
},
created:function(){
console.log('2-created 創(chuàng)建完成');
},
beforeMount:function(){
console.log('3-beforeMount 掛載之前');
},
mounted:function(){
console.log('4-mounted 被創(chuàng)建');
},
beforeUpdate:function(){
console.log('5-beforeUpdate 數(shù)據(jù)更新前');
},
updated:function(){
console.log('6-updated 被更新后');
},
activated:function(){
console.log('7 keep-alive組件激活時調(diào)用涵妥。該鉤子在服務(wù)器端渲染期間不被調(diào)用 ');
},
deactivated:function(){
console.log('8 keep-alive組件停用時調(diào)用。該鉤子在服務(wù)端渲染期間不被調(diào)用。');
},
beforeDestroy:function(){
console.log('9-beforeDestroy 銷毀之前');
},
destroyed:function(){
console.log('10-destroyed 銷毀之后')
}
})
</script>
</body>
</html>
參考文章
https://blog.csdn.net/qq_24147051/article/details/81167093