Skip to content

Image ​

Enhanced image component with loading skeleton, error fallback, lightbox preview, captions, and lazy loading.

Mountain
vue
<script setup lang="ts">
import { VxImage } from 'veloxui'
</script>

<template>
  <VxImage src="https://picsum.photos/300/200" alt="Mountain" :width="280" :height="180" :radius="8" />
</template>

Object Fit ​

Control how the image fills its container with the fit prop.

cover
cover
contain
contain
fill
fill
none
none
scale-down
scale-down
vue
<template>
  <VxImage src="..." fit="cover" />
  <VxImage src="..." fit="contain" />
  <VxImage src="..." fit="fill" />
  <VxImage src="..." fit="none" />
  <VxImage src="..." fit="scale-down" />
</template>

Preview (Lightbox) ​

Enable preview to allow clicking the image to open a full-screen lightbox. Press Escape or click outside to close.

Landscape
City
New York City at sunset
vue
<script setup lang="ts">
import { VxImage } from 'veloxui'
</script>

<template>
  <!-- Click to open lightbox -->
  <VxImage src="https://picsum.photos/800/500" preview />

  <!-- With caption in lightbox -->
  <VxImage src="..." preview caption="New York City at sunset" />
</template>

Caption ​

Nature
A peaceful mountain lake
Architecture
Photo by VeloxUI Team
vue
<template>
  <!-- String caption -->
  <VxImage src="..." caption="A peaceful mountain lake" />

  <!-- Custom caption slot -->
  <VxImage src="...">
    <template #caption>
      <span>Photo by <strong>VeloxUI Team</strong></span>
    </template>
  </VxImage>
</template>

Border Radius ​

vue
<template>
  <VxImage src="..." :radius="0" />     <!-- sharp -->
  <VxImage src="..." :radius="8" />     <!-- rounded -->
  <VxImage src="..." :radius="16" />    <!-- more rounded -->
  <VxImage src="..." radius="50%" />    <!-- circle -->
</template>

Error Fallback ​

When the image fails to load, shows a placeholder. Provide a fallback URL for an alternative image, or use the error slot for custom content.

Default error
Fallback image
Custom error slot
vue
<template>
  <!-- Default error state -->
  <VxImage src="https://broken.url" />

  <!-- Fallback image -->
  <VxImage src="https://broken.url" fallback="https://picsum.photos/200/140" />

  <!-- Custom error slot -->
  <VxImage src="https://broken.url">
    <template #error>
      <div>Image unavailable</div>
    </template>
  </VxImage>
</template>

Lazy Loading ​

Add lazy to defer loading until the image enters the viewport. Uses native loading="lazy".

vue
<template>
  <VxImage src="https://picsum.photos/800/500" lazy />
</template>

Srcset & Sizes ​

Provide responsive sources for retina and different viewport sizes.

vue
<template>
  <VxImage
    src="photo-400.jpg"
    srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1200.jpg 1200w"
    sizes="(max-width: 600px) 400px, (max-width: 1000px) 800px, 1200px"
  />
</template>

Props ​

PropTypeDefaultDescription
srcstring''Image source URL
altstring''Alt text
widthnumber | string—Image width
heightnumber | string—Image height
fit'cover' | 'contain' | 'fill' | 'none' | 'scale-down''cover'Object-fit mode
lazybooleanfalseNative lazy loading
previewbooleanfalseEnable lightbox on click
fallbackstring''Fallback image URL on error
radiusnumber | string0Border radius
srcsetstring''Responsive srcset
sizesstring''Responsive sizes
captionstring''Caption text below image

Events ​

EventTypeDescription
load(event)Image loaded successfully
error(event)Image failed to load
close()Preview lightbox closed

Slots ​

SlotDescription
errorCustom error state content
captionCustom caption content

ImageViewer ​

Full-screen image viewer with zoom, rotate, flip, pan, keyboard navigation, thumbnails, and gallery support.

Click any image to open the viewer. Use arrow keys, mouse wheel to zoom, and drag to pan.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VxImage, VxImageViewer } from 'veloxui'

const viewerOpen = ref(false)
const viewerIdx = ref(0)

const gallery = [
  { src: 'https://picsum.photos/800/600?10', caption: 'Mountain sunrise' },
  { src: 'https://picsum.photos/800/600?11', caption: 'Ocean waves' },
  { src: 'https://picsum.photos/800/600?12', caption: 'Forest trail' },
  { src: 'https://picsum.photos/800/600?13', caption: 'City skyline' },
  { src: 'https://picsum.photos/800/600?14', caption: 'Desert dunes' },
]

function openAt(i: number) {
  viewerIdx.value = i
  viewerOpen.value = true
}
</script>

<template>
  <VxImage v-for="(img, i) in gallery" :key="i" :src="img.src"
    :width="120" :height="90" :radius="8"
    @click="openAt(i)" style="cursor: pointer;" />

  <VxImageViewer
    v-model="viewerOpen"
    :images="gallery"
    :initial-index="viewerIdx"
    show-thumbnails
  />
</template>

Simple (String Array) ​

Pass an array of URL strings for quick usage.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VxImageViewer, VxButton } from 'veloxui'

const open = ref(false)
</script>

<template>
  <VxButton @click="open = true">Open Viewer</VxButton>

  <VxImageViewer
    v-model="open"
    :images="[
      'https://picsum.photos/800/600?20',
      'https://picsum.photos/800/600?21',
      'https://picsum.photos/800/600?22',
    ]"
  />
</template>

With Thumbnails ​

vue
<template>
  <VxImageViewer :images="gallery" show-thumbnails />
</template>

Keyboard Shortcuts ​

KeyAction
←Previous image
→Next image
+ / =Zoom in
-Zoom out
RRotate right 90deg
0Reset (fit to screen)
EscClose viewer

Toolbar Actions ​

The toolbar includes: zoom out, zoom percentage, zoom in, rotate left, rotate right, flip horizontal, flip vertical, reset to fit.

Mouse wheel zooms in/out. When zoomed past 100%, click and drag to pan the image.

ImageViewer Props ​

PropTypeDefaultDescription
images(string | ImageViewerItem)[][]Array of image URLs or objects
modelValuebooleanfalseShow/hide viewer (v-model)
initialIndexnumber0Starting image index
zoomStepnumber0.25Zoom increment per step
minZoomnumber0.5Minimum zoom level
maxZoomnumber5Maximum zoom level
loopbooleantrueLoop navigation at ends
showToolbarbooleantrueShow bottom toolbar
showCounterbooleantrueShow "1 / 5" counter
showThumbnailsbooleanfalseShow thumbnail strip

ImageViewer Events ​

EventTypeDescription
update:modelValue(boolean)Viewer opened/closed
change(index: number)Active image changed
close()Viewer closed

ImageViewerItem Interface ​

ts
interface ImageViewerItem {
  src: string
  alt?: string
  caption?: string
}

Exposed Methods ​

MethodDescription
prev()Go to previous image
next()Go to next image
goTo(index)Jump to specific image
zoomIn()Zoom in by zoomStep
zoomOut()Zoom out by zoomStep
rotateLeft()Rotate 90deg counter-clockwise
rotateRight()Rotate 90deg clockwise
reset()Reset zoom, rotation, flip, pan
close()Close the viewer