VirtualScroll (虚拟滚动)
只会渲染可见的内容,支持动态增删内容
支持平台
安卓 | ios | 鸿蒙 | web | 微信小程序 |
---|---|---|---|---|
√ | √ | √ | √ | √ |
示例代码
html
<template>
<t-page main-class="p-30">
<t-card main-class="tdr tdb mb-30" title="VirtualScroll 虚拟滚动" sub-title="亮点:支持动态增删数据,自研列表渲染算法"></t-card>
<t-virtual-scroll main-class="mb-30 tdr tdb" :list="list" item-class="" :row-height="115">
<template v-slot:default="{item,index}">
<t-row main-class="tdr oh tdb faic h-90%">
<t-lazy>
<t-image :src="`${(item as UTSJSONObject)['goods_img']}`" main-class="twh-130"></t-image>
</t-lazy>
<t-col main-class="p-30 f">
<t-text main-class="slh-50 w-100%">{{(item as UTSJSONObject)['goods_name']}}</t-text>
<t-text main-class="slh-50">索引:{{index}}</t-text>
<t-text mode="price" type="error" :text="`${(item as UTSJSONObject)['shop_price']}`"
:decimals="2"></t-text>
</t-col>
</t-row>
</template>
</t-virtual-scroll>
<t-button type="p" main-class="mb-30" @click="add">增加数据</t-button>
<t-button type="p" main-class="mb-30" @click="del">删除数据</t-button>
</t-page>
</template>
<script setup>
import { TuiApi } from '@/api'
const list = ref<UTSJSONObject[]>([])
TuiApi('getTestGoodsList', { "current": 1, "pageSize": 500, "goodsids": [] as Array<number>, devstatus: 'completed' }, true).then((res) => {
list.value = res.getArray('data.data.list') as UTSJSONObject[]
})
function add() {
TuiApi('getTestGoodsList', { "current": 1, "pageSize": 20, "goodsids": [] as Array<number> },true).then((res) => {
list.value.push(...(res.getArray('data.data.list') as UTSJSONObject[]))
})
}
function del() {
list.value.splice(0, 10)
}
</script>
属性
名称 | 类型 | 默认值 | 说明 | 可选值 |
---|---|---|---|---|
size | String | mini | 组件尺寸 | large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你) |
type | String | "" | 组件类型 | info(信息), primary(正常), error(错误), warning(警告), success(成功) |
disabled | Boolean | false | 组件是否禁用 | false, true |
stop | Boolean | false | 是否阻止事件冒泡(Tui统一写法处理事件冒泡) | false, true |
hover | Boolean | true | 是否有点击效果 | false, true |
path | String | "" | 点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。 | - |
mainClass | String | "" | 组件根节点的样式 | - |
nativeClass | String | "" | 组件根节点原生样式 | - |
effect | String | "normal" | 组件显示主题 | normal(正常), dark(深色), light(浅色), plain(镂空) |
rowHeight | Number | 120 | 每行的高度 | |
itemClass | String | `` | 行盒的样式 | |
list | any[] | [] | 数据源 | |
scrollTop | Number | 1 | 滚动位置 |
事件
名称 | 返回参数 | 说明 |
---|---|---|
scrollend | - | 滚动到底部时触发 |
插槽
名称 | 返回值 | 说明 |
---|---|---|
default | - |