Appearance
List 列表
模板标签:<qtx-list>
纵向/网格列表,是 qtx 里使用面最广的组件。支持多行模板、横向嵌套子列表、portal 活内容坑位、分页追加、焦点定位。完整定义见下文「API 参考」与独立 API 页(由源码自动生成)。
适用场景与限制
- 适用:板块流首页、收藏网格、频道内容、任何「一组同构数据 → 一组卡片」的场景。
- 适用:
#item内再嵌一层qtx-list做横向子列表(纵向 feed 里嵌横排)。 - 不适用:单个静态卡片(直接写
qt-text/qt-image)、播放器(由宿主 ES SDK 提供)、页面级 tab 容器(用QtxTabs)。
Web 演示
Web 演示浏览器模拟演示 · TV 真机行为以实机为准
4 行
热播推荐
本周更新 12 部
猜你在追
续播第 8 集
免费专区
无需会员
双片连看
两部长片连播
选中项:(无) · 核心能力:行模板、网格列数、点击 / 聚焦事件、流式追加、触底分页。
最近事件:—
基础示例
以下示例来自本目录下的真实文件:
vue
<template>
<div class="page" :width="1920" :height="1080">
<qt-text text="QtxList · 基础示例" :width="900" :height="60" />
<qtx-list :items="rows" :columns="2" key-field="id" :width="1920" :height="960">
<template #item="{ item }">
<div :width="900" :height="240">
<qt-text :text="item.title" :width="900" :height="60" />
<qt-text :text="item.subtitle" :width="900" :height="50" />
</div>
</template>
</qtx-list>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
// 数组即数据源:往末尾 push 会走原子追加,不闪、不丢焦点与滚动位。
const rows = ref([
{ id: '1', title: '热播推荐', subtitle: '本周更新 12 部' },
{ id: '2', title: '猜你在追', subtitle: '续播第 8 集' },
{ id: '3', title: '免费专区', subtitle: '无需会员' },
{ id: '4', title: '双片连看', subtitle: '两部长片连播' },
])
</script>TV 装饰预设(decoration)
生成 TV 首页/多 Tab 内容页时,写 decoration="tv" 让列表内部套用内容边界(左右 116 / 上下 56px)与卡间距 / 行间距(16 / 32px),列表尺寸不变、可全屏,业务不用再手写 margin / gutter 魔法数字:
vue
<qtx-list
decoration="tv"
:items="rows" :columns="6" key-field="id"
:width="1920" :height="948"
/>decoration默认none(保持原行为,不写的老页面逐像素不变)。- 边界内聚在 list 内部,不要给
qtx-list写 margin、也不要给qtx-tab-content写 padding / margin(根节点不生效)。 decoration="tv"不改变columns:列数与span仍由业务数据决定。- 需要微调卡间距时显式写
gutter(>0 时覆盖预设里的卡间值)。 - 完整取值表、页面级节奏数值(导航↔内容 32 / 工具条 72 / 标题↔内容 24 / 版块 32)与可复制最简页面见TV 装饰预设。
数据驱动与命令式 API
默认 :items 数组是权威,改数组会自动同步。命令式入口 setListData(items) / clearItems() 以传入数组为权威快照;父组件替换 :items 引用才回到 props 驱动。空数组会走同实例反射清空(S-029 修复后不再残留旧卡片)。
注意:
prependItems/moveItemBefore/dispatchAction目前仍以当前数据源重建为准,调用前请同步维护本地数组。
内容状态(loading / 空态 / 错误态)
用 state 表达首屏三态,业务不需要在 qtx-tab-content 里用 v-if 把 qtx-list 换成普通 div。组件内部始终同一个列表,只是把 items 换成一行内置 text 样式行:
vue
<qtx-list
:state="panelState"
:items="rows"
emptyText="这个目录还没有内容"
loadingText="正在读取文件…"
errorText="读取失败,点击重试"
:columns="3" key-field="id" :width="1920" :height="876"
/>| 属性 | 作用 |
|---|---|
state | ready(默认,用 items)/ loading / empty / error |
emptyText / loadingText / errorText | 各状态显示文本,有默认值 |
切换 state 走同一实例的全量重设(不卸载列表、不切换节点类型),因此焦点与滚动位不会因空态来回跳。配合 qtx-tabs 的 children 契约 使用时,可以让 qtx-tab-content 的子节点恒为「工具条 + qtx-list」,避免子节点类型切换。
使用约束与易错点
| 现象 | 原因与处理 |
|---|---|
| 卡片只显示第一行或裁切 | 必须给列表容器显式 height;可用高 = 页高 − 顶栏 − 状态条 |
| 模板写法「未生效」 | 查构建输出的 [QTX-T-EXPR];诊断会精确到属性所在行与实例序号,见 模板能力矩阵 |
#item="{ item: c }" 里 c.xxx 报错 | 内层插槽别名必须写成解构重命名形态,简写 { sub } 不是合法别名 |
| 嵌套子列表滚动/裁切异常 | 内层需要 clipChildren / clipPadding(布尔值),这是编译期白名单属性 |
| 触底追加进页就触发 | 首次 onScrolled(0,0) 会满足阈值(S-021,已定语义待 B3 落地),板块流建议加守卫 |
已知边界
- 全量重建丢焦点与滚动位;高频更新(倒计时类)暂不可用。
- 板块内多卡点击目前只有行级粒度,无子卡身份。
- 嵌套含内层列表时,非空数据的重设仍走整树重建(同实例反射对内层有引擎竞态风险)。
- 双引号文本经 JSON/编译通道会被截断(
edge.E4-quotes),见 工程总览。
验证状态
关联套件:gate / nested / complex / mixed / portal / fav / stress / ops / layout2。最近一次全量回归见 docs/QTX_LIST_VERIFY_S029.json(201/202 断言、28/28 套件全绿、fail=0 / blocked=0)。
API 参考
以下表格由
npm run docs:gen从源码生成,禁止手工编辑;完整独立页见 List 列表 API。
属性(Props · 16)
| 属性名 | 类型 | 必填 | 默认值 | 说明 | 事实源 |
|---|---|---|---|---|---|
columns | number | 否 | 1 | 列数:1 = 纵向列表,N = 网格(默认 1;decoration 不改变列数) | ts-types |
decoration | 'none' | 'tv' | QtxDecorationSpec | 否 | - | 内置装饰预设:'none' 保持原行为,'tv' 套用内容边界与间距;也可给数值对象覆盖 | ts-types |
direction | 'vertical' | 'horizontal' | 否 | vertical | 滚动方向(默认 'vertical';'horizontal' 随 M3 提供) | ts-types |
emptyText | string | 否 | - | state=empty 时显示文本,默认「暂无内容」 | ts-types |
errorText | string | 否 | - | state=error 时显示文本,默认「加载失败,点击重试」 | ts-types |
gutter | number | 否 | 0 | 单元格间距(px,默认 0;显式写 >0 时覆盖 decoration 预设里的卡间值) | ts-types |
initData | string | 否 | - | 原生直通属性(内部):{"templates":[...],"items":[...]} 原子初始化载荷。 由组件内部捕获管线生成,业务侧无需传。 | ts-types |
initialFocusIndex | number | 否 | 0 | 初始焦点行索引(默认 0) | ts-types |
itemAspectRatio | number | 否 | - | 单元格宽高比(与 columns 共同推导高度) | ts-types |
itemHeight | number | 否 | - | 单元格定高(px,网格必填或与 itemAspectRatio 二选一) | ts-types |
items | QtxListItem[] | 否 | - | 行数据(普通响应式数组,可直接变更;捕获期可后置填充) | ts-types |
keyField | string | 否 | id | itemId 锚点字段名(默认 'id';缺失时组件按索引生成稳定 id) | ts-types |
loadingTail | boolean | 否 | - | B2-1:loading 尾卡开关(C 方案)。开启时 load-more 触发自动显示尾卡、数据到达自动隐藏;默认关闭 | ts-types |
loadingText | string | 否 | - | state=loading 时显示文本,默认「加载中…」 | ts-types |
pageEnabled | boolean | 否 | false | 启用触底分页(触发 load-more 事件,默认 false) | ts-types |
state | 'ready' | 'loading' | 'empty' | 'error' | string | 否 | ready | 内容状态:ready 用 items;loading / empty / error 由组件内部生成状态行。同一列表换 items,不切换节点类型,业务无需在 qtx-tab-content 里写 v-if。默认 ready | ts-types |
事件(Events · 11)
| 事件名 | 载荷参数 | 说明 | 事实源 |
|---|---|---|---|
@capture-diagnostics | — | - | vue-sfc |
@item-bind | — | - | ts-types |
@item-click | — | - | ts-types+vue-sfc |
@item-focus | — | - | ts-types+vue-sfc |
@item-unbind | — | - | ts-types |
@load-more | — | - | ts-types+vue-sfc |
@nested-item-click | — | - | vue-sfc |
@nested-item-focus | — | - | vue-sfc |
@onItemEvent | — | - | vue-sfc |
@portal-viewport-enter | — | - | vue-sfc |
@portal-viewport-leave | — | - | vue-sfc |
方法(Methods / Expose · 13)
| 方法名 | 参数 | 返回值 | 说明 | 事实源 |
|---|---|---|---|---|
addListData | items: QtxListItem[] | Promise<void> | 追加数据(APPEND_SUB_ITEMS) | ts-types |
clearItems | — | Promise<void> | 清空列表(等价 setListData([]),空数据走同实例反射清空) | ts-types |
dispatchAction | actions: unknown | void | 通用指令入口(当前实现等价全量刷新) | ts-types |
focusItem | index: number | Promise<void> | 滚动到可见并聚焦指定行(TAB 切换后落列表首项的官方姿势) | ts-types |
getNativeNode | — | any | 取原生节点代理(Base→gate→$el,带 nodeId) | ts-types+vue-sfc |
moveItemBefore | from: number, to: number | void | 移动行到目标行之前;from/to 以当前 items 序为准,业务须在改本地数组前调用 | ts-types |
prependItems | items: QtxListItem[] | void | 头部插入(下拉刷新语义);业务须同步维护本地数组,结构性操作走重建 | ts-types |
refresh | — | void | 以下发数据整体刷新(重建通道) | ts-types |
removeItem | index: number | Promise<void> | 删除指定行;删除前把焦点迁移到相邻幸存行,避免焦点抖动 | ts-types |
scrollToIndex | index: number, smooth?: boolean | Promise<void> | 滚动到指定行(smooth=false 立即定位) | ts-types |
setListData | items: QtxListItem[] | Promise<void> | 全量重设(以传入数组为权威快照;空数组即清空;替换 :items 引用可回到 props 驱动) | ts-types |
setLoading | visible: boolean | Promise<void> | 手动控制 loading 尾卡;hasMore=false 时置 false 可抑制触底反复重显 | ts-types |
updateItem | index: number, patch: Partial<QtxListItem> | Promise<void> | 单行增量更新(等价 items[index] 局部赋值,走 UPDATE_ITEM) | ts-types |
插槽(Slots · 3)
| 插槽名 | 说明 | 事实源 |
|---|---|---|
default | 默认内容插槽,承载组件子内容 | js/qtx/src/components/QtxList/QtxListBase.vue |
item | 列表行模板插槽,作用域参数包含 item / index | docs-site/components/qtx-list/examples/basic.vue |
portals | Portal 活内容挂载插槽,需配合 v-portal-to 使用 | js/qtx/src/components/QtxList/QtxList.vue |