# vue-load-image

> A vue component for showing loader during image loading

Latest version **0.2.0** (published 2021-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-load-image
pnpm add vue-load-image
yarn add vue-load-image
bun add vue-load-image
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-06-27 |
| First published | 2018-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 68 |
| Author | Sangwon Lee |
| Maintainers | john015 |
| Keywords | vue-component, vue, vue-image-loader, image-loader, loader, image, image-preloader |

## Links

- npm: https://www.npmjs.com/package/vue-load-image
- Repository: https://github.com/john015/vue-load-image
- Homepage: https://github.com/john015/vue-load-image#readme
- Issues: https://github.com/john015/vue-load-image/issues
- npm.io page: https://npm.io/package/vue-load-image

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2021-06-27
- 1.1.0 (next) — 2021-06-27
- 1.0.1 — 2021-06-27
- 1.0.0 — 2021-06-27
- 0.1.12 — 2020-12-09
- 0.1.11 — 2020-07-11
- 0.1.10 — 2020-05-03
- 0.1.9 — 2019-11-27
- 0.1.8 — 2019-06-08
- 0.1.7 — 2019-01-09
- 0.1.61 — 2019-01-08
- 0.1.6 — 2018-12-12
- 0.1.56 — 2018-11-22
- 0.1.55 — 2018-11-22
- 0.1.5 — 2018-11-21
- … 5 more at https://npm.io/package/vue-load-image/versions

## README

English | [한국어](./README-ko.md)

# Vue-load-image

[![npm](https://img.shields.io/npm/dt/vue-load-image.svg)](https://www.npmjs.com/package/vue-load-image) ![npm bundle size (minified)](https://img.shields.io/bundlephobia/minzip/vue-load-image.svg) [![npm version](https://img.shields.io/npm/v/vue-load-image.svg?style=flat)](https://www.npmjs.com/package/vue-load-image) [![NpmLicense](https://img.shields.io/npm/l/vue-load-image.svg)](https://github.com/john015/vue-load-image/blob/master/LICENSE)

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](https://john015.github.io/vue-load-image/) / [(Source Code)](https://github.com/john015/vue-load-image/tree/master/example) 

## Installation

### Via NPM:

```bash
# for Vue 2.x
npm i vue-load-image 

# for Vue 3.x
npm i vue-load-image@next
```

### Via CDN:

```html
<!-- 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

```js
<template>
  <div>
    <vue-load-image>
      <img slot="image" src="./image.png"/>
      <img slot="preloader" src="./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

```js
<template>
  <div>
    <vue-load-image>
      <template v-slot:image>
        <img src="./image.png"/>
      </template>
      <template v-slot:preloader> 
        <img src="./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

```js
<template>
  <div>
    <vue-load-image>
      <div slot="image" style="background-image: url(./image.png)" data-src='./image.png' />
      <img slot="preloader" src="./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

```js
<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="./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.

---
_Source: https://npm.io/package/vue-load-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
