Skip to content

H5预览

APP下载

List 列表

List 组件用于展示一系列的数据项,支持自定义样式、交互操作和数据渲染。

cl-list

列表容器组件,用于展示多个列表项。

基础参数

参数说明类型可选值默认值
pt样式透传配置PassThrough--
list列表数据源ClListItem[]-[]
title列表标题string--
border是否显示边框boolean-false

PassThrough

样式透传配置对象,用于深度自定义组件内部元素的样式。

参数说明类型
className组件根元素样式string
list列表容器配置PassThroughProps
item列表项配置ClListItemPassThrough
ts
type ClListItemPassThrough = {
  className?: string;
  inner?: PassThroughProps;
  label?: PassThroughProps;
  content?: PassThroughProps;
  icon?: ClIconProps;
  collapse?: PassThroughProps;
};

cl-list-item

列表项组件,用于展示单个数据项,支持图标、箭头、滑动操作等功能。

基础参数

参数说明类型可选值默认值
pt样式透传配置PassThrough--
icon左侧图标名称string--
label标签文本string--
justify内容对齐方式"start" | "center" | "end"start / center / endend
arrow是否显示右侧箭头booleantrue / falsefalse
swipeable是否支持滑动操作booleantrue / falsefalse
hoverable是否显示点击态booleantrue / falsefalse
disabled是否禁用状态booleantrue / falsefalse
collapse是否支持折叠展开booleantrue / falsefalse

PassThrough

样式透传配置对象,用于深度自定义组件内部元素的样式。

参数说明类型
className组件根元素的 CSS 类名string
inner内部容器样式配置PassThroughProps
label标签文本样式配置PassThroughProps
content内容区域样式配置PassThroughProps
icon图标样式配置ClIconProps
collapse折叠内容样式配置PassThroughProps

使用示例

基础用法

最简单的列表项用法,包含标签和内容。

html
<cl-list-item label="用户名">
  <cl-text>神仙都没用</cl-text>
</cl-list-item>

内容对齐

通过 justify 属性控制内容的对齐方式。

html
<cl-list-item label="QQ" justify="start">
  <cl-text>615206459</cl-text>
</cl-list-item>

带箭头指示

设置 arrow 属性显示右侧箭头,通常用于表示可点击跳转。

html
<cl-list-item label="年龄" arrow>
  <cl-text>18</cl-text>
</cl-list-item>

带图标

通过 icon 属性添加左侧图标,增强视觉效果。

html
<cl-list-item label="余额" icon="wallet-line">
  <cl-text>10,000</cl-text>
</cl-list-item>

折叠展开

设置 collapse 参数并使用 #collapse 插槽实现折叠展开功能。

html
<cl-list-item label="点击展开" collapse arrow>
  <template #collapse>
    <view class="bg-surface-100 dark:bg-surface-700 p-3 rounded-xl">
      <cl-text>
        云想衣裳花想容,春风拂槛露华浓。若非群玉山头见,会向瑶台月下逢。
      </cl-text>
    </view>
  </template>
</cl-list-item>

滑动操作

设置 swipeable 参数并使用 #swipe-right#swipe-left 插槽实现滑动操作功能。

html
<!-- 左滑显示编辑按钮 -->
<cl-list-item label="左滑编辑" swipeable>
  <template #swipe-right>
    <view
      class="bg-green-500 w-20 h-full flex flex-row items-center justify-center"
    >
      <text class="text-white text-md">编辑</text>
    </view>
  </template>
</cl-list-item>

<!-- 右滑显示删除按钮 -->
<cl-list-item ref="listItemRef" label="右滑删除" swipeable>
  <template #swipe-left>
    <view
      class="bg-red-500 w-20 h-full flex flex-row items-center justify-center"
      @tap="onDelete"
    >
      <text class="text-white text-md">删除</text>
    </view>
  </template>
</cl-list-item>

列表容器

使用 cl-list 组件创建带标题和边框的列表容器。

html
<cl-list border title="功能">
  <cl-list-item label="我的订单" hoverable></cl-list-item>
  <cl-list-item label="我的收藏" hoverable></cl-list-item>
  <cl-list-item label="我的钱包" hoverable></cl-list-item>
</cl-list>

数据驱动渲染

通过 :list 属性传入数据数组,实现批量渲染。需要定义 ClListItem 类型。

html
<cl-list border title="功能" :list="list"></cl-list>

<script lang="ts" setup>
  import { ref } from "vue";
  import { type ClListItem } from "@/uni_modules/cool-ui";

  const list = ref<ClListItem[]>([
    {
      label: "我的订单",
    },
    {
      label: "我的收藏",
    },
    {
      label: "我的钱包",
      content: "10,000.00",
    },
  ]);
</script>