vue-onload
A lightweight image loader plugin for Vue.js with Typescript support
Installation
npm install vue-onload --save
How to use
Default use in your main.js Vue project
... ...
You can use the directive 'v-onload' in your HTML template
<template>
<div>
<img alt="My Image" class="img" v-onload="/static/images/my-image-01.jpg">
</div>
</template>
Which will be transformed once the resource has been loaded into:
<template>
<div>
<img alt="My Image" class="img" width="1024" height="768" src="/static/images/my-image-01.jpg">
</div>
</template>
A 'data-src' attribute will be added to replace the directive and will be removed once the image is loaded so CSS selector can be used to display smoothly the element like:
Preload
You can import preload
in your Vue script to preload an array of image sources.
name: 'MyComponent' { const loaded = return loaded }