infinite list based on vue2.
npm i vue-infinite-list
npm run start
import and register the infinite list component.
import InfiniteList from 'vue-infinite-list'
Vue.component(InfiniteList.name, InfiniteList)
use it in you app, pass the list item component and spinner component to infinite list component, config the props.
<template>
<div id="app">
<infinite-list @load="load" :list-item="listItem" :spinner="loadSpinner" :container-height="containerHeight" :item-height="itemHeight" :items="items" :loading="loading">
</infinite-list>
</div>
</template>
<script>
import ListItem from './ListItem.vue'
import LoadSpinner from './LoadSpinner.vue'
export default {
data() {
return {
listItem: ListItem,
loadSpinner: LoadSpinner
}
},
methods: {
load() {
//...
}
}
// ...
}
</script>
the list item component
this load spinner component
the height of the list container
the height of the item
array of list items.
list item data must contain a unique id which used as the key.
the list is split to many blocks of the same height(blockFactor * containerHeight)
the extra height(extendFactor * containerHeight) should render
the loading status
notify the parent component to load more list items