Registry / web-framework / vue-load-image

vue-load-image

JSON →
library0.2.0jsnpmunverified

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.

npm install vue-load-image
INSTALL
IMPORT
SIG · VUE-LOAD-IMAGE
V
vue-load-image
web-frameworkjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

VueLoadImage
import VueLoadImage from 'vue-load-image';
import { VueLoadImage } from 'vue-load-image';
The component is exported as a default export, so curly braces should not be used for direct import.
Component Registration (Local)
export default { components: { 'vue-load-image': VueLoadImage } }
export default { components: { VueLoadImage } }
While shorthand registration `VueLoadImage` might work, explicitly naming it `'vue-load-image'` aligns with the conventional usage demonstrated in the package's documentation for Vue 2.x templates.
Component Registration (Global)
import VueLoadImage from 'vue-load-image'; Vue.component('vue-load-image', VueLoadImage);
Vue.component(VueLoadImage.name, VueLoadImage);
Global registration directly registers the component under the specified tag name, making it available throughout your Vue instance without local import in every component.

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>
Debug
Known issues
breakingThis version (0.2.0) is built for Vue 2.x, which reached End-of-Life (EOL) in December 2023. Using this package in a new Vue 3 project will lead to incompatibility and runtime errors due to breaking changes in Vue's API between major versions.
fix
For Vue 3 projects, consider using `vue-load-image@next` (if actively maintained) or alternative image loading solutions designed for Vue 3. For existing Vue 2 projects, be aware of security implications of using EOL software.
affects: >=0.2.0
gotchaDynamic image paths (e.g., from data or props) in Vue 2 often require specific handling with `require()` or `new URL()` within templates or script blocks, especially when images are located in the `src/assets` directory and processed by webpack/Vue CLI. Directly using a string path like `src="./assets/my-image.png"` might not work in production builds.
fix
For local assets, use `require('./assets/my-image.png')` within your data properties or computed properties, or ensure paths are correctly resolved by your build tool. For dynamic public assets, place them in the `public` folder and reference them from the root, e.g., `/img/my-image.png`.
affects: >=0.2.0
deprecatedThe component itself shows no active maintenance for the Vue 2.x branch since approximately five years ago, aligning with the end of Vue 2 support. This means no new features, bug fixes, or security patches will be released for this version.
fix
Evaluate the need for this specific functionality against the risks of using unmaintained software. Consider migrating to a more actively maintained Vue 3 compatible library for image loading, or implementing similar functionality manually if the project requires long-term support.
affects: 0.2.0
gotchaStyling the preloader and error slots requires careful consideration. The default component provides structural slots, but no inherent styling. Developers must apply their own CSS to ensure the loader is visible, centered, and visually appealing, and that the error message is clearly formatted.
fix
Apply custom CSS to the elements within the `preloader` and `error` slots. Use `display: block; margin: auto;` or flexbox/grid for centering. Ensure appropriate `width`, `height`, and `background` styles are set for visual feedback during loading.
affects: >=0.2.0
Errors
Common errors & fixes
[Vue warn]: Unknown custom element: <vue-load-image>
The `vue-load-image` component was not properly imported or registered in the Vue component where it's being used.
fix
Ensure you have `import VueLoadImage from 'vue-load-image';` in your script and `components: { 'vue-load-image': VueLoadImage }` in your component's options or registered globally using `Vue.component('vue-load-image', VueLoadImage);` in your main.js file.
GET http://localhost:8080/image.png 404 (Not Found)
The image `src` provided to the `img` tag within the `image` slot is incorrect or the image file does not exist at the specified path, especially when dealing with local assets in a Vue CLI project.
fix
Double-check the image path. For images in `src/assets`, use `require('./assets/image.png')` or import them directly. For images in the `public` directory, use an absolute path like `/image.png`. Verify the image file exists and its filename matches exactly.
The preloader doesn't appear, or the image just flashes briefly before loading.
The preloader image/content is either not styled correctly to be visible, or the main image loads too quickly for the preloader to be meaningfully displayed, often due to local caching or very fast network conditions.
fix
Ensure your preloader content has distinct styling (e.g., background color, `width`, `height`, `text-align: center`). You can temporarily add a `setTimeout` around the image `src` assignment in the component's internal logic (if modifying source) or simulate network delay in browser developer tools to observe the preloader behavior. For very fast loads, the preloader might intentionally be skipped or barely visible as part of a good UX.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
vuerequiredRuntime dependency; the component is built for Vue 2.x environments.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vue-load-image — npm install vue-load-image · libregistry