<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue生命周期</title>
</head>
<body>
<div id="demo">
<button @click="distroy()">destroy vm</button>
<p v-show="isShow">what i want to do</p>
</div>
</body>
<script src="../../js/vue.js"></script>
<script type="text/javascript">
new Vue({
el:"#demo",
data:{
isShow: true
},
beforeCreate(){
console.log("beforeCreate创建前状态")
},
created(){
console.log("created创建完毕状态")
},
beforeMount(){
console.log("beforeMount挂载前状态")
},
mounted(){
//定时器
this.a = setInterval(()=> {
console.log("mounted 挂载结束状态")
this.isShow = !this.isShow
},1000)
},
beforeUpdate(){
console.log("beforeUpdate 更新前状态")
},
updated(){
console.log("updated 更新完成状态")
},
destroyed(){
console.log("beforeDestroy 销毁前状态")
},
beforeDestroy(){
clearInterval(this.a)
console.log("destroyed 销毁完成状态")
},
methods: {
distroy() {
this.$destroy()
}
}
})
</script>
</html>
vue生命周期总结
最新推荐文章于 2025-03-12 19:15:28 发布