Swipe 스와이프
Swipe는 셀 컴포넌트를 왼쪽·오른쪽으로 밀어서 작업 버튼을 보여주고 싶을 때 쓰는 컴포넌트예요. 목록 항목에서 '삭제', '즐겨찾기' 버튼을 숨겨뒀다가 꺼내 쓰는 패턴이 대표적이죠.
출처: 문서
본문
설치
@nutui/nutui에서 컴포넌트를 가져와 앱에 등록하면 바로 쓸 수 있어요.
import { createApp } from 'vue'
import { Swipe } from '@nutui/nutui'
const app = createApp()
app.use(Swipe)
사용 예시
기본 사용법
demo: swipe basic
비활성화
demo: swipe disabled
왼쪽 또는 오른쪽으로 스와이프
demo: swipe direction
Ref 메서드
demo: swipe methods
콘텐츠 커스터마이즈
demo: swipe content
SwipeGroup으로 하나만 열리게 만들기
Swipe의 name prop이 반드시 필요해요.
demo: swipe lock
Swipe
Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| name | identifies | string | - |
| disabled | Whether to disabled swipe | string | false |
| touch-move-prevent-default | Whether to stop touchmove event preventdefault | boolean | false |
| touch-move-stop-propagation | Whether to stop touchmove event propagation | boolean | false |
Events
| Event | Description | Arguments |
|---|---|---|
| click | click event | name, position: 'left' | 'content' | 'right' |
| open | Emitted when Swipe is opened, swipe left/swipe right | name, position: 'left' | 'right' |
| close | Emitted when Swipe is closed, swipe left/swipe right | name, position: 'left' | 'right' |
Slots
| Name | Description |
|---|---|
| left | Custom left |
| default | Custom default |
| right | Custom right |
Methods
ref로 Swipe 인스턴스를 얻은 뒤 인스턴스 메서드를 호출하세요.
| Name | Description | Arguments |
|---|---|---|
| open | open swipe, swipe left/swipe right | name, position: 'left' | 'right' |
| close | close swipe, swipe left/swipe right | name, position: 'left' | 'right' |
SwipeGroup
Props
| Attribute | Description | Type | Default |
|---|---|---|---|
lockv4.1.1 |
When a child Swipe opens, others will close. | boolean | false |
Types v4.3.3
이 컴포넌트는 아래 타입 정의를 함께 내보내요.
import type {
SwipePosition,
SwipeProps,
SwipeInstance,
SwipeGroupProps,
SwipeGroupInstance
} from '@nutui/nutui'
더 알아보기 (Learn more)
- 원문 문서: NutUI Swipe 공식 문서(영문)
- NutUI는 JD.com이 공개한 Vue 3 모바일 컴포넌트 라이브러리예요. 전체 컴포넌트 목록은 공식 문서 사이트에서, 소스 코드는 GitHub 저장소에서 볼 수 있어요.