Answer the question
In order to leave comments, you need to log in
How to track page scroll for only one vue component that keeps state (keep-alive)?
There is a vue component with articles. It has a keep-alive state . When scrolling to the end of the page, articles are automatically loaded from the database. The EventListener is responsible for this:
created() {
// load the data initially
this.fetchData();
window.addEventListener('scroll', this.handleScroll);
},
handleScroll() {
if ((!this.EndOfDataBase) && ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight - 50) && (!this.l
oading)) {
this.fetchDataNext()
}
},
destroyed() {
window.removeEventListener('scroll', this.handleScroll);
}
Answer the question
In order to leave comments, you need to log in
The component is also written to remove the "EventListener", but since the component retains its state (keep-alive), this method does not remove the "scroll listener".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question