跳到主要内容

滑动单元格 SwipeCell

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

安装使用

import { TiSwipeCell } from '@titian-design/mobile-vue';

用法示例

基本使用

<template>
<TiSwipeCell>
<div slot="left" class="left">left</div>
<div class="center">center</div>
<div slot="right" class="right">right</div>
</TiSwipeCell>
</template>

<script lang="ts" setup>
import { TiSwipeCell } from '@titian-design/mobile-vue';
</script>

<style>
.left,
.right {
height: 100px;
width: 100px;
}
.center {
height: 100px;
width: 100%;
}
</style>

自定义左右宽度

<template>
<TiSwipeCell :left-width="200">
<div slot="left" class="left">left</div>
<div class="center">center</div>
</TiSwipeCell>

<TiSwipeCell :right-width="200">
<div class="center">center</div>
<div slot="right" class="right">right</div>
</TiSwipeCell>
</template>

<script lang="ts" setup>
import { TiSwipeCell } from '@titian-design/mobile-vue';
</script>

<style>
.left,
.right {
height: 100px;
}

.center {
height: 100px;
width: 100%;
}
</style>

禁用滑动

<template>
<TiSwipeCell disabled>
<div slot="left" class="left">left</div>
<div class="center">center</div>
<div slot="right" class="right">right</div>
</TiSwipeCell>
</template>

<script lang="ts" setup>
import { TiSwipeCell } from '@titian-design/mobile-vue';
</script>

<style>
.left,
.right {
height: 100px;
width: 100px;
}
.center {
height: 100px;
width: 100%;
}
</style>

异步操作控制

<template>
<TiButton @click="handleClick">控制</TiButton>
<TiSwipeCell :visible="visible">
<div slot="left" class="left">left</div>
<div class="center">center</div>
</TiSwipeCell>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { TiSwipeCell, TiButton } from '@titian-design/mobile-vue';

const visible = ref<boolean>(false)

const handleClick = () => {
visible.value = !visible.value
}
</script>

<style>
.left {
height: 100px;
width: 100px;
}
.center {
height: 100px;
width: 100%;
}
</style>

监听事件

<template>
<TiSwipeCell
@open="handleOpen"
@close="handleClose"
@ti-click="handleTiClick"
>
<div slot="left" class="left">left</div>
<div class="center">center</div>
</TiSwipeCell>
</template>

<script lang="ts" setup>
import { TiSwipeCell } from '@titian-design/mobile-vue';

const handleOpen = (e: CustomEvent<OpenParams>) => {
console.log("打开", e);
};

const handleClose = (e: CustomEvent<CloseParams>) => {
console.log("关闭", e);
};

const handleTiClick = (e: CustomEvent<left | right | outside | cell>) => {
console.log("点击事件触发了", e);
};
</script>

<style>
.left {
height: 100px;
width: 100px;
}
.center {
height: 100px;
width: 100%;
}
</style>

TiSwipeCell API

属性 Properties

名称类型必填默认值说明备注
left-widthnumber0左边滑动区域宽度-
right-widthnumber0右边滑动区域宽度-
visiblebooleanfalse设置可滑动区域划开会先从左边到右开始查找是否有内容用于展示
disabledbooleanfalse禁止滑动-
async-closebooleanfalse是否异步关闭-
namestring-唯一标识-

事件 Events

事件名参数说明备注
open(e: CustomEvent<OpenParams>) => void打开时触发-
close(e: CustomEvent<CloseParams>) => void关闭时触发-
ti-click(e: CustomEvent<left | right | outside | cell >) => void点击时触发关闭时的点击位置 (left right cell outside)

OpenParams

interface OpenParams {
position: Position;
name: string;
}

CloseParams

interface CloseParams {
position: ClickPosition;
name: string;
instance: TiSwipeCell;
}

插槽 Slots

名称说明备注
right右侧内容-
left左侧内容-

可扩展样式名 External Class

名称说明备注
ext-class根节点可扩展的类名-