Skip to content

Image

Display images with lazy loading, fit modes, and fallbacks.

Basic Usage

vue
<template>
  <bp-image
    width="300px"
    height="200px"
    src="https://cos.birdpaper.design/birdpaper-ui/v2/image-demo/img_1.jpg?imageMogr2/thumbnail/!80p"
    alt="Sample image"
  />
</template>

Fit Mode

fit maps to CSS object-fit: fill, contain, cover, none, scale-down.

fill

contain

cover

none

scale-down

vue
<template>
  <div class="demo-area">
    <div class="fit-item" v-for="fit in fitTypes" :key="fit">
      <p>{{ fit }}</p>
      <bp-image
        width="80px"
        height="80px"
        :fit
        src="https://cos.birdpaper.design/birdpaper-ui/v2/image-demo/img_1.jpg?imageMogr2/thumbnail/!80p"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
const fitTypes = ["fill", "contain", "cover", "none", "scale-down"];
</script>

<style lang="scss" scoped>
.demo-area {
  display: flex;
  gap: 16px;
  .fit-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;

    p {
      color: #8c8c8c;
      font-size: 13px;
    }
  }
}
</style>

Fallback

Handle load failures with fallback or the error slot.

vue
<template>
  <bp-space :size="16">
    <bp-image
      width="200px"
      height="150px"
      src="https://invalid-url/broken.jpg"
      fallback="https://cos.birdpaper.design/birdpaper-ui/v2/image-demo/img_1.jpg?imageMogr2/thumbnail/!80p"
    />
    <bp-image width="200px" height="150px" src="https://invalid-url/broken.jpg">
      <template #error>
        <div class="error-slot">
          <IconCloseCircleLine size="28" />
          <span>Load failed</span>
        </div>
      </template>
    </bp-image>
  </bp-space>
</template>

<script setup lang="ts">
import { IconCloseCircleLine } from "birdpaper-icon";
</script>

<style lang="scss" scoped>
.error-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #c9cdd4;
  gap: 4px;

  span {
    font-size: 12px;
  }
}
</style>

Load Effect

load-effect supports fade, blur, and none.

fade

blur

none

vue
<template>
  <div class="demo-area">
    <div class="effect-item">
      <p>fade</p>
      <bp-image
        width="200px"
        height="140px"
        src="https://cos.birdpaper.design/birdpaper-ui/v2/image-demo/img_1.jpg?imageMogr2/thumbnail/!80p"
        load-effect="fade"
      />
    </div>
    <div class="effect-item">
      <p>blur</p>
      <bp-image
        width="200px"
        height="140px"
        src="https://cos.birdpaper.design/birdpaper-ui/v2/image-demo/img_1.jpg?imageMogr2/thumbnail/!80p"
        load-effect="blur"
      />
    </div>
    <div class="effect-item">
      <p>none</p>
      <bp-image
        width="200px"
        height="140px"
        src="https://cos.birdpaper.design/birdpaper-ui/v2/image-demo/img_1.jpg?imageMogr2/thumbnail/!80p"
        load-effect="none"
      />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.demo-area {
  display: flex;
  gap: 16px;

  .effect-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;

    p {
      color: #8c8c8c;
      font-size: 13px;
    }
  }
}
</style>

Image Props

srcImage source URL
String
--
altAlt text
String
--
titleImage title
String
--
widthImage width (CSS units supported)
String
--
heightImage height (CSS units supported)
String
--
fitObject-fit mode (same as CSS object-fit)
String
fill-
fallbackFallback image URL on error
String
--
lazyWhether to enable lazy loading
Boolean
--
placeholderPlaceholder image URL for lazy loading
String
--
load-effectLoad animation effect
String
fade-

Image Events

loadTriggered when the image finishes loadingev: Event-
errorTriggered when the image fails to loadev: Event-

Image Slots

loadingPlaceholder while loading--
errorContent shown on load error--