主要是整理一下关于window的监听事件,因为其他人写的都是单个,我在这里做一个整理
窗口监听事件
第一种方法: 在beforeDestroy钩子函数里销毁
mounted() {
window.addEventListener('resize', this.chartResize);
}
beforeDestroy() {
window.removeEventListener('resize', this.chartResize);
}
其他文章
https://blog.csdn.net/qq_38892710/article/details/107518260
页面滚动监听事件
mounted() {
window.addEventListener('scroll', this.scrollToTop);
}
beforeDestroy() {
window.removeEventListener('scroll', this.scrollToTop);
}
其他文章
https://blog.csdn.net/a772116804/article/details/115556449
键盘鼠标事件
mounted () {
window.addEventListener('keyup',this.handleKeyup)
window.addEventListener('scroll',this.handleScroll)
},
destroyed () {
window.removeEventListener('keyup',this.handleKeyup)
window.removeEventListener('scroll',this.handleScroll)
},
其他文章
https://www.ucloud.cn/yun/103870.html