Skip to content

MazLazyImg ​

MazLazyImg is a standalone component to display images and svgs with lazy loading

Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started

vue
<script setup lang="ts">
import MazLazyImg from 'maz-ui/components/MazLazyImg'
</script>

<template>
  <MazLazyImg src="https://placedog.net/1000/1000" block />
</template>

Performance

MazLazyImg relies on the vLazyImg directive, whose IntersectionObservers are pooled and shared across every instance - rendering many images (galleries, lists, avatars) stays cheap.

Responsive sources ​

Pass an object with sources to serve different images depending on the media query (like a native <picture>).

vue
<template>
  <MazLazyImg
    :src="{
      sources: [
        { srcset: 'https://placedog.net/600/400', media: '(max-width: 600px)' },
        { srcset: 'https://placedog.net/1500/1000', media: '(min-width: 601px)' },
      ],
    }"
    block
  />
</template>

Image height full ​

By default the image is displayed with width: 100%. Enable image-height-full to fill the height instead: the image keeps its aspect ratio, fills 100% of the height and overflows/crops horizontally. Handy for wide images or SVGs inside a fixed-height container.

vue
<template>
  <div style="height: 200px;">
    <MazLazyImg image-height-full src="https://placedog.net/1500/1000" />
  </div>
</template>

Fallback on error ​

Provide fallback-src to swap the image when it fails to load.

vue
<template>
  <MazLazyImg
    src="https://broken-link-image-src.example"
    fallback-src="https://placedog.net/500/500"
    block
  />
</template>

Without loader ​

Hide the spinner shown while the image is loading with hide-loader.

vue
<template>
  <MazLazyImg src="https://placedog.net/1000/1000" hide-loader block />
</template>

Props ​

NameDescriptionTypeRequiredDefaultPossible values
srcThe source of the imageMazImage | nullNo--
altThe alt of the imagestringNo--
hide-loaderRemove the loaderbooleanNo--
observer-onceRemove the observer once the image is loadedbooleanNotrue-
load-onceRemove the observer once the image is loadedbooleanNo--
image-height-fullMake the image height fullbooleanNo--
observer-optionsThe options of the observer{ root?: HTMLElement | null | undefined; threshold: number; rootMargin?: string | undefined; }No--
fallback-srcThe fallback src to replace the src on loading errorstringNo--
img-classThe classes of the image elementClassValueNo--
blockThe image will be displayed in full widthbooleanNo--

Events ​

Event namePayloadDescription
intersectingel: ElementEmitted when the image is intersecting
loadingel: ElementEmitted when the image is loading
loadedel: ElementEmitted when the image is loaded
errorel: ElementEmitted when the image is in error

Slots ​

NameDescriptionBindings
default-