组件库文档 tmui.design
虚拟列表 Virtual
用来展示长列表数据使用,采用虚拟数据展示,只展示视窗内数据,其它不展示。因此上万条列表数据,也可以轻松展示。
已经集成了下拉,触底加载整数事件,封装的非常简单。只要提供load事件即可异步加载数据啦。
🌶️ 虚拟列表 Virtual 示例
查看模拟效果+
示例模板
vue
<template>
<tm-app>
<tm-sheet>
<tm-text :font-size="30" _class="font-weight-b" label="基础示例,更多见文档,以下是展示你可以无限加载图片列表,你将看不到任何卡顿或者阻塞。超高性能的虚拟列表。"></tm-text>
<tm-divider></tm-divider>
<view class="flex flex-col flex-col-top-center">
<tm-virtual-list :load="getdata" :width="626" :height="900" :data="imglist" :itemHeight="160">
<template v-slot:default="{data}">
<tm-sheet :border="1" borderDirection="bottom" :height="160" :width="626" _class="flex flex-row flex-row-center-start" :padding="[0,0]" :margin="[0,0]" v-for="(item,index) in data" :key="index">
<view class="flex flex-row flex-row-center-between flex-1">
<tm-image :width="200" :height="100" :src="item.src" ></tm-image>
<tm-text :label="'image-Row-'+item.index"></tm-text>
</view>
</tm-sheet>
</template>
</tm-virtual-list>
</view>
</tm-sheet>
</tm-app>
</template>
<script lang="ts" setup>
import {
ref
} from "vue";
import {
onShow,
onLoad
} from "@dcloudio/uni-app";
import tmApp from "@/tmui/components/tm-app/tm-app.vue"
import tmSheet from "@/tmui/components/tm-sheet/tm-sheet.vue"
import tmText from "@/tmui/components/tm-text/tm-text.vue"
import tmImageGroup from "@/tmui/components/tm-image-group/tm-image-group.vue"
import tmImage from "@/tmui/components/tm-image/tm-image.vue"
import tmVirtualList from "@/tmui/components/tm-virtual-list/tm-virtual-list.vue"
import tmDivider from "@/tmui/components/tm-divider/tm-divider.vue"
const imglist = ref([])
const getdata = (e:string)=>{
return new Promise((res,rej)=>{
setTimeout(function() {
if(e=='top'){
imglist.value = []
for(let i=0;i<10;i++){
imglist.value.push({src:'https://i0.pickpik.com/photos/298/434/513/beach-dawn-dusk-ocean-thumb.jpg',index:i})
}
}else if(e=='bottom'){
let len = imglist.value.length;
for(let i=len;i<10+len;i++){
imglist.value.push({src:'https://i0.pickpik.com/photos/298/434/513/beach-dawn-dusk-ocean-thumb.jpg',index:i})
}
}
res(true)
}, 2500);
})
}
</script>
🌶️ 兼容性
APP-VUE | APP-NVUE | 小程序 | WEB/H5 | VUE3/TS |
---|---|---|---|---|
✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
🌱 参数
本组件含有公共属性 公共属性
参数名 | 类型 | 默认值 | 描述 |
---|---|---|---|
width | Number | 300 | 宽度,单位rpx |
height | Number | 500 | 高度,单位rpx |
topHeight | Number | 0 | 顶部自定义内容高度,单位rpx |
itemHeight | Number | 0 | 项目的高度 |
colorv3.0.7+ | String | "primary" | 加载图标的主题色 |
data | Array<string> | [] | 虚拟列表数据 |
firstLoadv3.0.7+ | Boolean` | true | 首次渲染时,是否触发load事件。 |
loadv3.0.7+ | Function,Boolean | ()=>true | 数据加载事件 |
load为数据加载事件,参数加载类型:bottom 触底加载, top 下拉加载
🌹 事件
事件名 | 参数 | 返回数据 | 描述 |
---|---|---|---|
@pull-startv3.0.7+ | - | - | 下拉时触发 |
@pull-endv3.0.7+ | - | - | 触底时触发 |
🌽 slot插槽
插槽名 | 数据 | 类型 | 描述 |
---|---|---|---|
top | - | - | 顶部自定义内容,高度不超过topHeight 设定高度 |
default | data | Arrray<any> | 默认插槽,主要 |
🥗 ref方法
无
💏 文档贡献
此页文档由夏天贡献,如果对该框架感兴趣的可以参与我们一同进步!