Skip to content

引入组件

局部引入

ts
// parent.vue
const FSwipeAction = defineAsyncComponent(() => import('@/components/formaui/f-swipe-action/f-swipe-action.vue'))

基础用法

items属性:右侧操作按钮列表,左滑展开

html
<f-swipe-action :items="items" @action-click="onActionClick">
  <f-cell>左滑显示操作按钮</f-cell>
</f-swipe-action>
ts
import { ref } from 'vue'

const items = ref([
  { label: '收藏', value: 'favorite', bgColor: '#C8C7CD', color: '#FFFFFF', width: '160rpx' },
  { label: '删除', value: 'delete', bgColor: 'var(--f-color-danger)', color: '#FFFFFF', width: '160rpx' }
])

const onActionClick = (detail: { index: number; value: string | number }) => {
  uni.showToast({ title: String(detail.value), icon: 'none' })
}

closeOnAction属性:点击按钮后是否自动关闭(默认true

html
<f-swipe-action :items="items" :close-on-action="false" @action-click="onActionClick">
  <f-cell>点击按钮后需点遮罩关闭</f-cell>
</f-swipe-action>

isMask属性:展开时是否显示遮罩(默认true

html
<f-swipe-action :items="items" :is-mask="false" @action-click="onActionClick">
  <f-cell>展开时可滑动其他项</f-cell>
</f-swipe-action>

disabled属性:是否禁止滑动(默认false

html
<f-swipe-action :items="items" disabled @action-click="onActionClick">
  <f-cell>无法左滑</f-cell>
</f-swipe-action>

v-model:open:手动控制展开/收起

html
<f-swipe-action v-model:open="manualOpen" :items="items" @action-click="onActionClick">
  <f-cell>可通过按钮控制展开</f-cell>
</f-swipe-action>
<f-button @click="manualOpen = !manualOpen">{{ manualOpen ? '收起' : '展开' }}</f-button>

插槽

名称说明
default滑动主体内容
actions自定义操作按钮区

使用 actions 插槽时,可通过 operateWidth 设置操作区宽度。

html
<f-swipe-action operate-width="200rpx">
  <f-cell>自定义按钮区域</f-cell>
  <template #actions>
    <view class="flex-1 flex items-center justify-center bg-[var(--f-color-danger)] text-white">删除</view>
  </template>
</f-swipe-action>

属性

名称类型说明默认值
items{label:string;
value:string/number;
color?:string;
fontSize?:string;
width?:string;
bgColor?:string;
icon?:string;
iconWidth?:string;
iconHeight?:string}[]
右侧操作按钮列表[]
closeOnActionboolean点击按钮后是否自动关闭true
isMaskboolean展开时是否显示遮罩,点击遮罩关闭true
operateWidthstring使用 actions 插槽时的操作宽度160rpx
disabledboolean是否禁止滑动false
bgColorstring内容区背景颜色#FFFFFF
v-model:openboolean是否展开操作区false

事件

事件名说明回调参数
actionClick点击操作按钮{ index: number; value: string | number }

方法

方法名说明传入参数
close关闭操作菜单-