In my VueJS component, I have implemented a scroll event that triggers an AJAX call to update the Jobs()
function when the user is getting close to the end of the page.
if ( windowScrollTop >= (documentHeight - windowHeight - 50) )
{
this.updateJobs();
}
Everything seems to be working fine as the jobs are updated and displayed. However, there's one issue - the updates don't stop and keep loading until all pages of data are fetched.
I expected the updating process to halt after the first round since the condition in the if
statement would no longer be met. But apparently, the scroll event continues triggering without taking into account the new position and height values with the additional data included.
Is it a good idea to use setTimeout
to allow time for rendering? Or should I explore other alternatives for managing this repetitive update behavior?