Learn how to implement a simple infinite scroll for your Vue apps using nothing but some vanilla JavaScript and a simple Random User API.
Infinite scrolls have their place on the web, but it aren’t for every website or application. They’re especially useful when you need to load large amounts of data or images when the user needs them rather than at all once. Social media outlets like Twitter, Facebook, and Instagram have popularized this over the years. Integrating your own infinite scroll on your website or application is easier than you might think.
This article is going to be using the Random User API. The API describes itself as “Like Lorem Ipsum, but for people”. It’s not only great for this implementation, but it’s also very useful for mocking up user profiles for future projects.
Before you start, create a new Vue.js project using the Vue CLI template. This example will be using Axios and MomentJS for data fetching and date formatting, respectively.
There are various npm packages for infinite scroll that you can use for your Vue app, but some of these may be overkill. For this post, we’ll go without a plugin or package and we’re going to be writing a simple JavaScript function that fetches a new set of data when scrolled to the bottom of the browser window.
Before we start integrating the infinite scroll, let’s fetch and set some initial data on page load:
It’s worth noting that it’s not recommended to make…