Skip to content

pinholucas/v-img-fallback

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm bundle size GitHub license Vue3

Vue Image Fallback

for Vue 3



📄 Description

v-img-fallback

Vue image placeholder directive for broken images.

If you like this project, please give it a star, and consider following the author. :)

⚙️ Install & Usage

Install with NPM or Yarn

npm install v-img-fallback --save

yarn add v-img-fallback

Install globally

import { createApp } from 'vue';
import VueImgFallback from 'v-img-fallback';

const app = createApp({})

app.use(VueImgFallback, {
  loading: 'path/to/loading/image',
  error: 'path/to/error/image'
});

Install locally

<template>
  <img src="foo.png" v-img-fallback="imgFallback">
</template>

<script>
import { ImgFallback } from 'v-img-fallback';

export default {
  directives: {
    ImgFallback
  },
  data: () => {
    imgFallback: {
      loading: 'path/to/loading/image',
      error: 'path/to/error/image'
    }
  }
};
</script>

API

This directive can receive string or object value.

string

Path or image url. This value will be used in both loading and error state.

object

{
  loading: 'path/to/loading/image',
  error: 'path/to/error/image'
}

Sample - pass a string

<template>
  <img src="foo.png" v-img-fallback="path/to/placeholder">
</template>

Sample - pass an object

<template>
  <img src="foo.png" v-img-fallback="imgFallback">
</template>

<script>
  export default {
    data: () => {
      imgFallback: {
        loading: 'path/to/loading/image',
        error: 'path/to/error/image'
      }
    }
  }
</script>

Tips

loading value can be a .gif Gee. Ahy. Ef. (I will die with dignity LOL).

**Made with ❤️ by Jofferson Ramirez Tiquez & ported to Vue 3 by Lucas Pinho (its not a big thing, k) **

About

Vue Image Fallback

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%