跳到主要内容

SwipeCell 滑动单元格 ​

uni-appH5微信小程序App

跨端列表滑动操作容器,支持右侧操作插槽和程序化开关。

何时使用 ​

列表项需要隐藏的快捷操作(删除、置顶、标记已读)时。

何时不使用 ​

操作需要始终可见时用普通按钮;操作超过 3 个时用 ActionSheet。

本文档为 uni-app 端组件契约;Web 端同名组件 API 可能略有差异,请以对应包文档为准。下方手机预览实时运行 uni-app H5 演示。

9:41
SwipeCell 滑动单元格 · uni-app H5 实时运行 新窗口打开

Props ​

名称类型默认值说明
disabledbooleanfalse禁用滑动
thresholdnumber30松手后判定「展开」所需滑动的距离(px),超过则吸附展开,否则弹回
actionWidthnumber120右侧操作区宽度,单位 px

Events ​

名称载荷说明
openvoid操作区完全展开时触发
closevoid操作区收起(弹回 / 点击内容收起 / 程序化 close)时触发

Slots ​

名称说明
default单元格内容
right右侧操作区

Methods ​

名称签名说明
open--
close--

示例 ​

左滑操作 ​

vue
<SwipeCell>
  <Cell title="消息通知" value="左滑试试" />
  <template #right><view class="row">
    <Button variant="secondary" size="sm">置顶</Button>
    <Button variant="danger" size="sm">删除</Button>
  </view></template>
</SwipeCell>

列表组合 ​

vue
<Stack :gap="10">
  <SwipeCell>
    <Cell title="会话 A" value="左滑操作" />
    <template #right><Button variant="danger" size="sm">删除</Button></template>
  </SwipeCell>
  <SwipeCell>
    <Cell title="会话 B" value="左滑操作" />
    <template #right><Button variant="secondary" size="sm">已读</Button></template>
  </SwipeCell>
</Stack>

自定义阈值 ​

vue
<SwipeCell :threshold="40" :action-width="140">
  <Cell title="自定义手感" value="更大触发阈值" />
  <template #right><Button variant="danger" size="sm">删除</Button></template>
</SwipeCell>