Vue Image Loader Component

0.2.0 · abandoned · verified Sun Apr 19

The `vue-load-image` package provides a minimalist Vue.js component designed to manage the loading state of images, enhancing user experience by displaying a preloader while an image fetches. This `0.2.0` version is specifically built for Vue 2.x applications. It allows developers to define custom content for the loading state (preloader) and an error state (alternate content) if the image fails to load. Weighing in at just 1KB gzipped, it's a very lightweight solution focused solely on image loading feedback. However, with its last substantial update being over five years ago, coinciding with the shift to Vue CLI, and its peer dependency on Vue 2.x (which reached End-of-Life in December 2023), this particular version is considered abandoned. While a `@next` tag exists for Vue 3, this entry pertains to the Vue 2 compatible `0.2.0` release. Key differentiators include its simplicity and direct slot-based customization for loading and error states, rather than complex lazy-loading or advanced progressive image techniques.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the basic usage of `vue-load-image` in a Vue 2.x application. It shows how to import and register the component, and then use its `image`, `preloader`, and `error` slots to display different content based on the image loading state, including a successful load and an intentional error scenario.

<!-- App.vue (or any Vue 2 component) -->
<template>
  <div id="app">
    <h1>Image Loading Demo</h1>
    <p>Using vue-load-image to display a loader while images load.</p>

    <h2>Example 1: Basic Image with Preloader and Error Slot</h2>
    <vue-load-image>
      <template v-slot:image>
        <img src="https://via.placeholder.com/400x200?text=Loaded+Image" alt="Loaded Image" />
      </template>
      <template v-slot:preloader>
        <img src="https://i.imgur.com/gKj31sO.gif" alt="Loading..." style="width: 100px; height: 100px;" />
      </template>
      <template v-slot:error>
        <div style="color: red; border: 1px solid red; padding: 10px;">Failed to load image!</div>
      </template>
    </vue-load-image>

    <h2>Example 2: Image with an intentionally broken URL</h2>
    <vue-load-image>
      <template v-slot:image>
        <img src="/non-existent-image.jpg" alt="Broken Image" />
      </template>
      <template v-slot:preloader>
        <p>Loading broken image...</p>
      </template>
      <template v-slot:error>
        <div style="background-color: #ffe0e0; padding: 10px;">Oops! This image couldn't be found.</div>
      </template>
    </vue-load-image>
  </div>
</template>

<script>
import VueLoadImage from 'vue-load-image';

export default {
  name: 'App',
  components: {
    'vue-load-image': VueLoadImage // Registering the component locally
  }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.vue-load-image {
  display: inline-block;
  margin: 20px;
  border: 1px solid #ccc;
  padding: 10px;
}
</style>

view raw JSON →