The source code for v-img-error a VueJS Directive.
A simple Vue directive to catch img errors & broken links and replace them with default or custom fallback image. NO dependencies!
If you like this project, please give it a star & consider following the author. :)
npm install v-img-error
main.js
import Vue from 'vue';
import vImgError from 'v-img-error';
Vue.use(vImgError)
component.vue
import { vImgError as imgError } from "v-img-error";
export default {
directives: {
imgError
}
}
<template>
<img src="myImg.png" v-img-error>
<img src="anotherImg.svg" v-img-error>
</template>
With your custom fallback Img:
<template>
<img src="myImg.png" v-img-error="path/to/image">
<img src="anotherImg.svg" v-img-error="path/to/svg">
</template>
MIT © Maor Barel