滑动操作组件,左右滑动拉出菜单栏
当前组件在 PC 端预览无法操作,请以实机效果为准
基本使用
使用 swipe-action
组件包裹需要滑动操作的内容,通过 actions
属性设置操作按钮。
html
<iui-swipe-action
:actions="[
{
icon: 'delete',
text: '删除',
style: { background: '#F53F3F' },
onClick: onClick,
},
]"
>
<iui-cell label="Single menu"></iui-cell>
</iui-swipe-action>
<script setup lang="ts">
const onClick = (text, index) => {
console.log("click", text, index);
};
</script>
<iui-swipe-action
:actions="[
{
icon: 'delete',
text: '删除',
style: { background: '#F53F3F' },
onClick: onClick,
},
]"
>
<iui-cell label="Single menu"></iui-cell>
</iui-swipe-action>
<script setup lang="ts">
const onClick = (text, index) => {
console.log("click", text, index);
};
</script>
自定义内容
在 actions
列表项中设置 slotName
属性, 通过插槽可以自定义滑动操作的内容。
html
<iui-swipe-action :actions="[{ slotName: 'del' }]">
<iui-cell label="Custom slot"></iui-cell>
<template #del>
<view
style="
background-color: #00b42a;
height: 100%;
width: 80px;
display: flex;
align-items: center;
justify-content: center;
color: white;
padding: 12px;
white-space: nowrap;
box-sizing: border-box;
"
>
<iui-icon name="smile"></iui-icon>
<view style="display: flex; align-items: center; padding-left: 5px"
>通过Slot自定义内容</view
>
</view>
</template>
</iui-swipe-action>
<iui-swipe-action :actions="[{ slotName: 'del' }]">
<iui-cell label="Custom slot"></iui-cell>
<template #del>
<view
style="
background-color: #00b42a;
height: 100%;
width: 80px;
display: flex;
align-items: center;
justify-content: center;
color: white;
padding: 12px;
white-space: nowrap;
box-sizing: border-box;
"
>
<iui-icon name="smile"></iui-icon>
<view style="display: flex; align-items: center; padding-left: 5px"
>通过Slot自定义内容</view
>
</view>
</template>
</iui-swipe-action>
API
<SwipeAction>
props<SwipeAction>
slots<Action>
props