From d740147184f7f54e1bb7ba0a89636dc14ce90405 Mon Sep 17 00:00:00 2001 From: kernoeb Date: Sat, 23 Sep 2023 15:23:47 +0200 Subject: [PATCH] chore: properly destroy event --- components/ScrollToTop.vue | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/components/ScrollToTop.vue b/components/ScrollToTop.vue index 9740da1..e9eb3db 100644 --- a/components/ScrollToTop.vue +++ b/components/ScrollToTop.vue @@ -33,14 +33,20 @@ export default { } }, mounted () { - document.addEventListener('scroll', (event) => { - if (typeof window === 'undefined') { return } - const top = window.pageYOffset || event.target.scrollTop || 0 - this.active = top > this.threshold - }) + document.addEventListener('scroll', this.checkScroll) }, beforeDestroy () { - document.removeEventListener('scroll', () => {}) + document.removeEventListener('scroll', this.checkScroll) + }, + methods: { + checkScroll (event) { + if (typeof window === 'undefined') { + return + } + + const top = window.pageYOffset || event.target.scrollTop || 0 + this.active = top > this.threshold + } } }