Skip to content

SwipeRow 滑动单元格

可以左右滑动来展示操作按钮的单元格组件。

导入

js
import SwipeRow from '@/components/feedback/SwipeRow.vue';

使用方法

基础用法

可以通过 leftActionsrightActions 属性快速配置左右滑动操作按钮,也可以通过插槽自定义内容。

vue
<template>
  <SwipeRow
    :leftActions="[{ text: '收藏', type: 'primary', onClick: () => toast?.info('点击了收藏') }]"
    :rightActions="[{ text: '标为已读', type: 'primary', onClick: () => toast?.info('点击了标为已读') }, { text: '删除', type: 'danger', onClick: () => toast?.info('点击了删除') }]"
  >
    <Cell title="单元格" value="内容" />
  </SwipeRow>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import SwipeRow from '@/components/feedback/SwipeRow.vue';
import Cell from '@/components/basic/Cell.vue';
import Toast, { type ToastInstance } from '@/components/feedback/Toast.vue';

const toast = ref<ToastInstance>();
</script>

自定义内容

通过插槽可以完全自定义左右滑动的内容,同时可以设置 leftWidthrightWidth 来指定滑动区域的宽度。

vue
<template>
  <SwipeRow
    :leftWidth="100"
    :rightWidth="140"
  >
    <template #left>
      <Text>内容内容内容内容内容内容</Text>
    </template>
    <FlexRow :gap="20" backgroundColor="white" :padding="20" :height="70">
      <Image src="https://imengyu.top/assets/images/test/1.jpg" :width="60" :height="60" />
      <Text>我是自定义渲染内容</Text>
    </FlexRow>
    <template #right>
      <Text>内容内容内容内容内容</Text>
      <Button shape="square" type="primary" text="确定" @click="toast?.info('点击了确定')" />
    </template>
  </SwipeRow>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import SwipeRow from '@/components/feedback/SwipeRow.vue';
import Text from '@/components/basic/Text.vue';
import FlexRow from '@/components/layout/FlexRow.vue';
import Image from '@/components/basic/Image.vue';
import Button from '@/components/basic/Button.vue';
import Toast, { type ToastInstance } from '@/components/feedback/Toast.vue';

const toast = ref<ToastInstance>();
</script>

API 参考

SwipeRowAction 类型

操作按钮的类型定义:

名称说明类型必填默认值
text操作按钮的文本string-
type操作按钮的类型ButtonType-
onClick操作按钮的点击事件(e: any) => void-

Props

名称说明类型必填默认值
leftWidth手动设置左侧宽度,单位为pxnumber-0
leftActions左侧操作按钮SwipeRowAction[]-[]
rightWidth手动设置右侧宽度,单位为pxnumber-0
rightActions右侧操作按钮SwipeRowAction[]-[]
disabled是否禁用boolean-false
autoClose是否点击后自动关闭boolean-true

Slots

名称说明
default默认内容区域,用于显示主要内容
left左侧滑动内容,显示在默认内容左侧
right右侧滑动内容,显示在默认内容右侧

Events

名称说明参数
click点击内容区域时触发$event