I'm using Vue3 and NuxtJS,but it seems like scroll event wont fire. Nothing happens after I scroll,nor I don't have any errors
methods: {
handleScroll () {
console.log('scrolled')
}
},
created(){
if(process.client){
window.addEventListener('scroll', this.handleScroll);
console.log(window)
}
},
destroyed () {
if(process.client){
window.removeEventListener('scroll', this.handleScroll);
}
}
I guess the problem is that your process.client is false.
I tried the code below and it works fine for me:
methods: {
handleScroll() {
console.log("scrolled");
},
},
created() {
window.addEventListener("scroll", this.handleScroll);
console.log(window);
},
destroyed() {
window.removeEventListener("scroll", this.handleScroll);
},
</js>