Try this:
<template>
<div>
<p v-if="!scrolledToBottom" class="cookie-policy">{{ cookiePolicy }}</p>
</div>
</template>
<script>
export default {
data: () => ({
scrolledToBottom: false,
}),
mounted() {
this.scroll()
},
methods: {
scroll() {
window.onscroll = () => {
const bottomOfWindow =
Math.max(
window.pageYOffset,
document.documentElement.scrollTop,
document.body.scrollTop
) +
window.innerHeight ===
document.documentElement.offsetHeight
if (bottomOfWindow) {
this.scrolledToBottom = true
}
}
},
},
}
</script>
Instead of v-if
you may prefer using v-show
depending of your usecase.
Source: Check if a user has scrolled to the bottom in Vue.js
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…