使用方法
//vue-virtual-scroll-list
<template>
<div>
<virtual-list style="height: 360px; overflow-y: auto;" // make list scrollable
:data-key="'id'"
:data-sources="items"
:data-component="itemComponent"
/>
</div>
</template>
<script>
import Item from './Item'
import VirtualList from 'vue-virtual-scroll-list'
function createData(len) {
const arr = []
for (let index = 0; index < len; index++) {
const obj = { id: index, text: Math.random() }
arr.push(obj)
}
return arr
}
export default {
name: 'root',
data () {
return {
itemComponent: Item,
items: createData(200)
}
},
components: { 'virtual-list': VirtualList }
}
</script>
// item
<template>
<div>每一行的内容</div>
</template>
<script>
export default {
name: 'item-component',
props: {
index: { // 每一行的索引
type: Number
},
source: { // 每一行的内容
type: Object,
default () {
return {}
}
}
}
}
</script>

image.png
如上图
他只渲染keeps传入的个数,滚动时通过改变padding的值来模拟滚动,里面的每一个item在滚动时动态替换里面的值