[Vuejs]-How can i do lazy loading images on vue3?

-2👍

You can use vue-lazyload library to do this.

1- First, install the packege using npm:

npm i vue-lazyload

2- After that add VueLazyload plugin to your Vue App:

import Vue from 'vue'
import App from './App.vue'
import VueLazyload from 'vue-lazyload'
 
Vue.use(VueLazyload)
 
// or with options
Vue.use(VueLazyload, {
  preLoad: 1.3,
  error: 'dist/error.png',
  loading: 'dist/loading.gif',
  attempt: 1
})
 
new Vue({
  el: 'body',
  components: {
    App
  }
})

3- Then you can use it every where:

<ul>
  <li v-for="img in list">
    <img v-lazy="img.src" >
  </li>
</ul>

Leave a comment