方法一
因为 keep-alive 组件
多了一个 activated 生命周期
多了一个 deactivated 生命周期 // 页面隐藏或被替换时调用
方法二
用 mounted & unmounted 生命周期
代码
mounted () {
window.addEventListener('scroll', this.handleScroll)
},
unmounted () {
window.removeEventListener('scroll', this.handleScroll)
}