Skip to content

Commit

Permalink
chore: properly destroy event
Browse files Browse the repository at this point in the history
  • Loading branch information
kernoeb committed Sep 23, 2023
1 parent 9cc8d2b commit d740147
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions components/ScrollToTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
</script>

0 comments on commit d740147

Please sign in to comment.