查漏补缺——说一下Vue生命周期的beforeDestroy生命周期函数?
问题
如题所示
答案
vue 如何控制组件初始与销毁_beforeDestroy:vue(组件)对象销毁之前
vue页面刷新时,执行了哪些生命周期——谨慎使用beforeDestroy和destroyed
Vue学习笔记3.2-生命周期函数 beforeCreate、created、beforeMount、Mounted、beforeUpdate、updated、beforeDestroy、destro
vue 生命周期 beforeDestroy 和 destroyed 调用
相关源码:
mounted() {
window.addEventListener('scroll', this.hzhScroll)
},
beforeDestroy () {
window.removeEventListener('scroll', this.hzhScroll)
}
这两句Vue生命周期钩子函数,分别是添加对对滚动条的监视器和移除对滚动条的监视器。
根据上面的,这里beforeDestroy()生命周期钩子函数会在Vue(组件)对象销毁之前执行,那么Vue(组件)对象会在什么时候销毁呢?
根据上面,我们可以知道Vue组件当页面关闭,路由跳转,组件会自动销毁等。