参考书籍《Vue.js快跑:构建触手可及的高性能Web应用》第1章 Vue.js基础-----1-18生命周期钩子
官网图:
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>生命周期钩子title>
head>
<body>
<div id="app">
<p>当前计数{{count}}p>
<button @click="count++">增加button>
div>
<script src="https://unpkg.com/vue">script>
<script>
let vue = new Vue({
el: "#app",
data: {
count: 0
},
beforeCreate(){
console.log("beforeCreate");
},
created(){
console.log("created");
},
beforeMount(){
console.log("beforeMount");
},
mounted(){
console.log("mounted");
},
beforeUpdate(){
alert("beforeUpdate");
},
updated(){
alert("upadted");
},
beforeDestroy(){
alert("beforeDestroy");
},
destroyed(){
alert("destroyed");
}
})
script>
body>
html>