Skip to content

SwipeCell - Vant 4

SwipeCell

Intro

Used for cell components that can slide left and right to display operation buttons.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { SwipeCell } from'vant'; const app = createApp(); app.use(SwipeCell);

Usage

Basic Usage

html

Custom Content

html

Before Close

html
js
import { showConfirmDialog } from'vant'; exportdefault { setup() { constbeforeClose = ({ position }) => { switch (position) { case'left': case'cell': case'outside': returntrue; case'right': returnnewPromise((resolve) => { showConfirmDialog({ title: 'Are you sure to delete?', }) .then(() =>resolve(true)) .catch(() =>resolve(false)); }); } }; return { beforeClose }; }, };

API

Props

AttributeDescriptionTypeDefault
nameIdentifier of SwipeCell, usually a unique string or number*numberstring*
left-widthWidth of the left swipe area*numberstring*
right-widthWidth of the right swipe area*numberstring*
before-closeCallback function before close*(args) => booleanPromise<boolean>*
disabledWhether to disabled swipebooleanfalse
stop-propagationWhether to stop touchmove event propagationbooleanfalse

Slots

NameDescription
defaultcustom content
leftcontent of left scrollable area
rightcontent of right scrollable area

Events

EventDescriptionArguments
clickEmitted when SwipeCell is clicked*position: 'left'
openEmitted when SwipeCell is opened*value: { name: string
closeEmitted when SwipeCell is closed*value: { name: string

beforeClose Params

AttributeDescriptionType
event v4.9.4The event object that triggers the closing action*MouseEvent
nameName*string
positionClick position*'left'

Methods

Use ref to get SwipeCell instance and call instance methods.

NameDescriptionAttributeReturn value
openopen SwipeCellposition: `leftright`
closeclose SwipeCell--

Types

The component exports the following type definitions:

ts
importtype { SwipeCellSide, SwipeCellProps, SwipeCellPosition, SwipeCellInstance, } from'vant';

SwipeCellInstance is the type of component instance:

ts
import { ref } from'vue'; importtype { SwipeCellInstance } from'vant'; const swipeCellRef = ref<SwipeCellInstance>(); swipeCellRef.value?.close();

Enterprise-level mobile solution based on Vant