AvatarCropper 아바타 크롭
AvatarCropper는 프로필 사진을 잘라서 새 이미지를 만들 때 쓰는 컴포넌트예요. NutUI 4.2.0 이상에서 쓸 수 있어요.
출처: 문서
설치
@nutui/nutui에서 컴포넌트를 가져와 앱에 등록하면 바로 쓸 수 있어요.
import { createApp } from 'vue'
import { AvatarCropper } from '@nutui/nutui'
const app = createApp()
app.use(AvatarCropper)
사용 예시
기본 사용법
가운데에 아바타 컴포넌트를 바로 두면, 크롭이 끝난 뒤 이미지 내용이 새 이미지로 교체돼요.
demo: avatarcropper basic
모양 v4.2.8
모양은 square, round 중에서 고를 수 있어요.
demo: avatarcropper shape
크롭 영역 툴바 슬롯
크롭 영역의 툴바를 커스터마이즈해요. toolbar-position으로 툴바 위치를 정할 수 있어요.
demo: avatarcropper toolbar
API
AvatarCropper Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| max-zoom | Maximum zoom | number | 3 |
| space | The gap reserved on both sides of the clipping area | number | 20 |
| toolbar-position | Location of the toolbar in the clipping area. The optional value is:top bottom |
string | bottom |
| edit-text | The text content in the middle | string | 编辑 |
| cancel-text | Cancel button text | string | 取消 |
| cancel-confirm | Confirm button text | string | 确认 |
shapev4.2.8 |
Shape of avatar. The optional value is: square、round |
string | square |
AvatarCropper Slots
| Name | Description |
|---|---|
| default | The default slot for placing elements such as images, ICONS, and text |
| toolbar | After selecting the file, crop the bottom element of the pop-up window can be customized, and invoke the method of the component through ref |
AvatarCropper Events
| Name | Description | Callback Arguments |
|---|---|---|
| confirm | Click Confirm to trigger after cropping | url:The trimmed base64 |
| cancel | Click cancel trigger | - |
AvatarCropper Ref
| Event | Explain |
|---|---|
| cancel | uncrop |
| reset | Reset to 0 degrees |
| rotate | Rotate 90 degrees |
| confirm | Definite cut |
더 알아보기 (Learn more)
- 원문 문서: NutUI AvatarCropper 공식 문서(영문)
- NutUI는 JD.com이 공개한 Vue 3 모바일 컴포넌트 라이브러리예요. 전체 컴포넌트 목록은 공식 문서 사이트에서, 소스 코드는 GitHub 저장소에서 볼 수 있어요.