This plugin is only 7.62kb uncompressed version, which is very simple and supports lazyloads for img tags and background-img resources. Supports 1.0 and 2.0
Keep it safe
$ npm install vue-lazyload --save
How to use
// import Vue from 'vue' // import VueLazyload import VueLazyload from 'vue-lazyload' //use custom directive (VueLazyload) // use options (VueLazyload, { preLoad: 1.3, error: 'dist/', loading: 'dist/', attempt: 1 }) new Vue({ el: 'body', })
<!----> <script> export default { data () { return { list: [ 'your_images_url', 'your_images_url', // you can customer any image's placeholder while loading or load failed { src: 'your_images_url.png', error: '', loading: '' } ] } } } </script> <template> <div class="img-list"> <ul > <li v-for="img in list"> <img v-lazy="img"> </li> </ul> </div> </template>
Here you can customize all styles that are loading in progress and loading failed and successful loading.
<style> img[lazy=loading] { /*your style here*/ } img[lazy=error] { /*your style here*/ }, img[lazy=loaded] { /*your style here*/ } /* or background-image */ .yourclass[lazy=loading] { /*your style here*/ } .yourclass[lazy=error] { /*your style here*/ }, .yourclass[lazy=loaded] { /*your style here*/ } </style>
API
Options
params | type | detail |
---|---|---|
preLoad | Number | proportion of pre-loading height |
error | String | error img src |
loading | String | loading img src |
attempt | Number | attempts count |
demo download address:vue-lazyloadz_jb51.rar
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.