Vue中使用keep-alive对组件进行缓存 ,exclude属性表示要去除被缓存的组件,其它组件都会被缓存。
当使用这个属性后,对应的这个组件的activated() deactivated()方法就不会执行了。
activated() {
window.addEventListener('scroll', this.handleScroll)
},
deactivated() {
window.removeEventListener('scroll', this.handleScroll)
}
修改为
mounted() {
window.addEventListener('scroll', this.handleScroll)
},
destroyed() {
window.removeEventListener('scroll', this.handleScroll)
}