Answer the question
In order to leave comments, you need to log in
How to request data only if the component is visible on the screen?
Page in the form of a tape of photos and likes to them. There are 2 photos on the screen, and there are more than 20 on the page. Information for each like is loaded separately. Perhaps there are ready-made components that monitor whether the component is visible on the screen. I want to request data from the server only when the user scrolls the page to each photo.
Answer the question
In order to leave comments, you need to log in
mounted() {
const observer = new IntersectionObserver(entries => {
if (entries[0].isIntersecting) {
stopObservation();
// здесь запрашивайте свои данные
}
}, {
threshold: 1,
});
observer.observe(this.$el);
const stopObservation = () => observer.disconnect();
this.$on('hook:beforeDestroy', stopObservation);
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question