Top Direction Scroll

Okay, it's time to try the top direction scroll list. This plugin will save and restore the scroll height automatically since v2.4.0, which means that the top direction feature can be used out of the box now!


  <!-- Hacker News header -->

<infinite-loading direction="top" @infinite="infiniteHandler"></infinite-loading>

<div v-for="(item, $index) in list" :key="$index">
  <!-- Hacker News item loop -->

In the template, we moved the InfiniteLoading component to the top of the news list, and set the direction property to top.


import axios from 'axios';

const api = '//';

export default {
  data() {
    return {
      page: 1,
      list: [],
  methods: {
    infiniteHandler($state) {
      axios.get(api, {
        params: {
      }).then(({ data }) => {
        if (data.hits.length) {
 += 1;
        } else {

The script part is almost the same as the basic Hacker News. The only difference is that we reverse the news data from the server and unshift it into the list. That's it! This plugin will do the remaining work, isn't it very easy?

Last Updated: 1/13/2019, 5:41:29 PM

An infinite scroll plugin for Vue.js

EN | 中文