vue-load-image

A vue component for showing loader during image loading
129,890 68
Install
npm install vue-load-image@next
Latest Version:1.1.0
Vue:3
Older releases:2
License:MIT
Last Updated:Jan 7, 2023
Links: GitHub  ·  npm
Maintainer: john015

English | 한국어

Vue-load-image

npm npm bundle size (minified) npm version NpmLicense

Vue-load-image is 1KB(gzipped size) minimalist Vue component that display loader during image loading and display alternate content when the image fails to load.

Demo

vue-load-image Demo / (Source Code)

Installation

Via NPM:

# for Vue 2.x
npm i vue-load-image 

# for Vue 3.x
npm i vue-load-image@next

Via CDN:

<!-- for Vue 2.x -->
<script src='https://unpkg.com/vue-load-image'></script>

<!-- for Vue 3.x -->
<script src='https://unpkg.com/vue-load-image@next'></script>

Usage

Image

Vue 2.x
<template>
  <div>
    <vue-load-image>
      <img slot="image" src="https://raw.githubusercontent.com/john015/vue-load-image/HEAD/image.png"/>
      <img slot="preloader" src="https://raw.githubusercontent.com/john015/vue-load-image/HEAD/image-loader.gif"/>
      <div slot="error">error message</div>
    </vue-load-image>
  </div>
</template>

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

export default {
  components: {
    'vue-load-image': VueLoadImage
  }
}
</script>
Vue 3.x
<template>
  <div>
    <vue-load-image>
      <template v-slot:image>
        <img src="https://raw.githubusercontent.com/john015/vue-load-image/HEAD/image.png"/>
      </template>
      <template v-slot:preloader> 
        <img src="https://raw.githubusercontent.com/john015/vue-load-image/HEAD/image-loader.gif" />
      </template>
      <template v-slot:error>Image load fails</template>
    </vue-load-image>
  </div>
</template>

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

export default {
  components: {
    'vue-load-image': VueLoadImage
  }
}
</script>

Background-image

Vue 2.x
<template>
  <div>
    <vue-load-image>
      <div slot="image" style="background-image: url(./image.png)" data-src='./image.png' />
      <img slot="preloader" src="https://raw.githubusercontent.com/john015/vue-load-image/HEAD/image-loader.gif" />
      <div slot="error">error message</div>
    </vue-load-image>
  </div>
</template>

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

export default {
  components: {
    'vue-load-image': VueLoadImage
  }
}
</script>
Vue 3.x
<template>
  <div>
    <vue-load-image>
      <template v-slot:image>
        <div style="background-image: url(./image.png)" data-src='./image.png' />
      </template>
      <template v-slot:preloader> 
        <img src="https://raw.githubusercontent.com/john015/vue-load-image/HEAD/image-loader.gif" />
      </template>
      <template v-slot:error>Image load fails</template>
    </vue-load-image>
  </div>
</template>

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

export default {
  components: {
    'vue-load-image': VueLoadImage
  }
}
</script>
⚠️Notice

Set data-src to be the same as background-image url

Events

Name Description
onError onError gets triggered when the image fails to load.
onLoad onLoad gets triggered when the image is loaded.

Slots

"image" slot will be rendered when the image is successfully loaded

"preloader" slot will be rendered when the image is in the process of loading

"error" slot will be rendered when the image load fails.

Related Packages

vue-inner-image-zoom

A Vue.js component for magnifying an image within its parent container 🔎

135,953 36
vue-json-tree-view

a JSON Tree View Component in Vue.js

380,792 473
@scayle/nuxt-image-provider

An image provider to handle SCAYLE-specific modifiers

99,945
@v-c/picker

picker ui component for vue

57,185 32

Version History

Version Released License
1.1.0 MIT
1.0.1 MIT
1.0.0 MIT
0.2.0 MIT
0.1.61 MIT