vue-virtual-scroll-list(利用padding填充)

使用方法

//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>每一行的內(nèi)容</div>
</template>
 
<script>
  export default {
    name: 'item-component',
    props: {
      index: { // 每一行的索引
        type: Number
      },
      source: { // 每一行的內(nèi)容
        type: Object,
        default () {
          return {}
        }
      }
    }
  }
</script>
image.png
如上圖

他只渲染keeps傳入的個數(shù),滾動時通過改變padding的值來模擬滾動,里面的每一個item在滾動時動態(tài)替換里面的值

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容