参考:vue官网 1、代码如下:
Vue_生命周期1
销毁
hello world
new Vue({
el:'#test',
data:{
isShow:true
},
mounted(){/*初始化显示后立即调用(调用1次)*/
this.intervalId=setInterval(()=> {
console.log("-----------")
this.isShow =!this.isShow
},1000)
},
beforeDestroy(){/*死亡之前调用(调用1次)*/
/*清楚定时器*/
clearInterval(this.intervalId)
},
methods:{/*销毁方法*/
destroy(){
this.$destroy()
}
}
})
2、效果图如下: