How to Use Vue Lazyload in a Nuxt Project demo repo

Vue Lazyload (opens new window) is a Vue.js plugin for lazyloading image or component.

# 👣 Steps

  1. Create a Nuxt project and install Vue Lazyload.
npx create-nuxt-app nuxt-demo
cd nuxt-demo
npm i vue-lazyload
  1. Put a placeholder image to load while loading, e.g. /assets/loading.svg. Put another to load upon load fail, e.g. /assets/error.svg.

  2. Create Vue Lazyload plugin in plugins/vue-lazyload.js. Pass the options (opens new window) you need there as well.

import Vue from "vue";
import VueLazyload from "vue-lazyload";

import error from "../assets/error.svg";
import loading from "../assets/loading.svg";

Vue.use(VueLazyload, {
  preLoad: 1,
  attempt: 1
  1. Register the plugin in nuxt.config.js.
export default {
  plugins: ["@/plugins/vue-lazyload"]
  1. Use Vue Lazyload, e.g. in pages/vue-lazyload.vue. I purposely made a typo in the first link so you can see how an error is shown in the demo.
    <h1>Vue Lazyload Demo</h1>

    <div class="grid">
        v-for="(item, index) in img"
        class="border-primary card"
        <b-img v-lazy="item" fluid />

export default {
  data() {
    return {
      img: [

<style lang="scss" scoped>
.grid {
  display: grid;
  row-gap: 2rem;

  @media (min-width: 768px) {
    grid-template-columns: 1fr 1fr;
    column-gap: 2.5rem;

.card {
  display: flex;
  align-items: center;
  justify-content: center;

# 📖 Explanation

# Settings

  • attempt limits the attempt to load images.
  • error shows a replacement image upon load fail.
  • loading shows another image while loading.
  • preLoad makes the pre-loading height the same as the actual image.

# Usage

Last updated: 11/1/2020, 3:28:11 PM