본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Vue Image 컴포넌트

원문 보기 위키 갱신

Image는 단일 이미지를 미리보기(preview)와 변형(transformation) 옵션과 함께 보여 주는 컴포넌트예요. 클릭하면 확대·회전 기능이 있는 모달 레이어가 열려요.

출처: 문서

본문

Vue Image Component

Displays a single image with preview and tranformation options.

Import

import Image from 'primevue/image';

Accessibility

Screen Reader 미리보기 버튼은 로케일 API의 aria.zoomImage 프로퍼티를 기본으로 참조하는 aria-label이 붙은 네이티브 button 요소이고, previewButtonProps를 사용하면 여러분만의 aria role과 속성을 쓸 수 있어요. 모든 유효한 속성은 button 요소로 그대로 전달되기 때문이에요. preview가 활성화되면 오버레이 이미지 컨테이너에 dialog role과 aria-modal이 적용돼요. 버튼 컨트롤은 로케일 API의 aria.rotateRight, aria.rotateLeft, aria.zoomIn, aria.zoomOut, aria.close를 aria-label로 사용해요. ButtonBar Keyboard Support preview가 활성화되면 닫기 버튼이 처음 포커스를 받아요. Key Function tab 버튼 바를 통해 포커스를 이동해요. enter 버튼을 활성화해요. space 버튼을 활성화해요. esc 이미지 미리보기를 닫아요.

Basic

Image는 표준 img 요소와 비슷하게 사용해요.

<Image src="/image.jpg" alt="Image" width="250" />

Preview

preview 모드를 활성화하면 이미지를 클릭했을 때 회전이나 확대 같은 변형 옵션을 제공하는 모달 레이어가 표시돼요.

<Image src="/image.jpg" alt="Image" width="250" preview />
Composition API Example
<template>
    <div class="card flex justify-center">
        <Image src="https://primefaces.org/cdn/primevue/images/galleria/galleria10.jpg" alt="Image" width="250" preview />
    </div>
</template>

Template

preview 모드에서 이미지에 마우스를 올리면 기본적으로 눈 아이콘이 표시되고, 커스텀 콘텐츠는 previewicon 슬롯을 사용해요. 또한 image와 preview 슬롯을 사용해 각각 썸네일과 상세 이미지를 정의할 수 있어요.

<Image alt="Image" preview>
    <template #previewicon>
        <i class="pi pi-search"></i>
    </template>
    <template #image>
        <img src="/thumbnail.jpg" alt="image" />
    </template>
    <template #preview="slotProps">
        <img src="/image.jpg" alt="preview" :style="slotProps.style" @click="slotProps.onClick" />
    </template>
</Image>
Composition API Example
<template>
    <div class="card flex justify-center">
        <Image alt="Image" preview>
            <template #previewicon>
                <i class="pi pi-search"></i>
            </template>
            <template #image>
                <img src="https://primefaces.org/cdn/primevue/images/galleria/galleria11.jpg" alt="image" width="250" />
            </template>
            <template #preview="slotProps">
                <img src="https://primefaces.org/cdn/primevue/images/galleria/galleria11.jpg" alt="preview" :style="slotProps.style" @click="slotProps.onClick" />
            </template>
        </Image>
    </div>
</template>

Image

Props

Name Type Default Description
src string - Image url.
preview boolean false Controls the preview functionality.
imageStyle any - Inline style of the image element.
imageClass any - Style class of the image element.
indicatorIcon string - Custom indicator icon.
previewIcon string - Custom indicator icon.
zoomInDisabled boolean false Disable the zoom-in button
zoomOutDisabled boolean false Disable the zoom-out button
dt any - It generates scoped CSS variables using design tokens for the component.
pt PassThrough - Used to pass attributes to DOM elements inside the component.
ptOptions any - Used to configure passthrough(pt) options of the component.
unstyled boolean false When enabled, it removes component related styles in the core.

Pass Through Options

Name Type Description
root ImagePassThroughOptionType Used to pass attributes to the root's DOM element.
image ImagePassThroughOptionType Used to pass attributes to the image's DOM element.
previewMask ImagePassThroughOptionType Used to pass attributes to the preview mask's DOM element.
previewIcon ImagePassThroughOptionType Used to pass attributes to the preview icon's DOM element.
mask ImagePassThroughOptionType Used to pass attributes to the mask's DOM element.
toolbar ImagePassThroughOptionType Used to pass attributes to the toolbar's DOM element.
rotateRightButton ImagePassThroughOptionType Used to pass attributes to the rotate right button's DOM element.
rotateRightIcon ImagePassThroughOptionType Used to pass attributes to the rotate right icon's DOM element.
rotateLeftButton ImagePassThroughOptionType Used to pass attributes to the rotate left button's DOM element.
rotateLeftIcon ImagePassThroughOptionType Used to pass attributes to the rotate left icon's DOM element.
zoomOutButton ImagePassThroughOptionType Used to pass attributes to the zoom out button's DOM element.
zoomOutIcon ImagePassThroughOptionType Used to pass attributes to the zoom out icon's DOM element.
zoomInButton ImagePassThroughOptionType Used to pass attributes to the zoom in button's DOM element.
zoomInIcon ImagePassThroughOptionType Used to pass attributes to the zoom in icon's DOM element.
closeButton ImagePassThroughOptionType Used to pass attributes to the close button's DOM element.
closeIcon ImagePassThroughOptionType Used to pass attributes to the close icon's DOM element.
originalContainer ImagePassThroughOptionType Used to pass attributes to the original container's DOM element.
original ImagePassThroughOptionType Used to pass attributes to the original's DOM element.
hooks any Used to manage all lifecycle hooks.
transition ImagePassThroughTransitionType Used to control Vue Transition API.

Theming

CSS Classes

Class Description
p-image Class name of the root element
p-image-preview-mask Class name of the preview mask element
p-image-preview-icon Class name of the preview icon element
p-image-mask Class name of the mask element
p-image-toolbar Class name of the toolbar element
p-image-rotate-right-button Class name of the rotate right button element
p-image-rotate-left-button Class name of the rotate left button element
p-image-zoom-out-button Class name of the zoom out button element
p-image-zoom-in-button Class name of the zoom in button element
p-image-close-button Class name of the close button element
p-image-original Class name of the original element

Design Tokens

Token CSS Variable Description
image.transition.duration --p-image-transition-duration Transition duration of root
image.preview.icon.size --p-image-preview-icon-size Icon size of preview
image.preview.mask.background --p-image-preview-mask-background Mask background of preview
image.preview.mask.color --p-image-preview-mask-color Mask color of preview
image.toolbar.position.left --p-image-toolbar-position-left Position left of toolbar
image.toolbar.position.right --p-image-toolbar-position-right Position right of toolbar
image.toolbar.position.top --p-image-toolbar-position-top Position top of toolbar
image.toolbar.position.bottom --p-image-toolbar-position-bottom Position bottom of toolbar
image.toolbar.blur --p-image-toolbar-blur Blur of toolbar
image.toolbar.background --p-image-toolbar-background Background of toolbar
image.toolbar.border.color --p-image-toolbar-border-color Border color of toolbar
image.toolbar.border.width --p-image-toolbar-border-width Border width of toolbar
image.toolbar.border.radius --p-image-toolbar-border-radius Border radius of toolbar
image.toolbar.padding --p-image-toolbar-padding Padding of toolbar
image.toolbar.gap --p-image-toolbar-gap Gap of toolbar
image.action.hover.background --p-image-action-hover-background Hover background of action
image.action.color --p-image-action-color Color of action
image.action.hover.color --p-image-action-hover-color Hover color of action
image.action.size --p-image-action-size Size of action
image.action.icon.size --p-image-action-icon-size Icon size of action
image.action.border.radius --p-image-action-border-radius Border radius of action
image.action.focus.ring.width --p-image-action-focus-ring-width Focus ring width of action
image.action.focus.ring.style --p-image-action-focus-ring-style Focus ring style of action
image.action.focus.ring.color --p-image-action-focus-ring-color Focus ring color of action
image.action.focus.ring.offset --p-image-action-focus-ring-offset Focus ring offset of action
image.action.focus.ring.shadow --p-image-action-focus-ring-shadow Focus ring shadow of action

더 알아보기 (Learn more)