Vue Loading Skeleton

1.1.9 · maintenance · verified Sun Apr 19

Vue Loading Skeleton is a component library designed for Vue 2 applications, specifically requiring `vue: ^2.6.11`. It offers a streamlined approach to creating animated loading skeleton screens. A key differentiator of this library is its `Skeleton` component's ability to automatically adapt to the dimensions and typography of the actual content it will eventually replace. This eliminates the manual effort often required to perfectly match font-sizes, margins, or line heights, as it intelligently derives these styles from the wrapped content's first child node. The library also includes a `SkeletonTheme` component, allowing developers to apply global styling parameters like color and animation duration across multiple `Skeleton` instances. The current stable version is 1.1.9, with its last major update occurring approximately six years ago. This indicates that the project is in a maintenance phase, primarily supporting its existing Vue 2 user base, rather than active development with new features. For Vue 3 projects, users should seek out more recently developed, Vue 3-compatible skeleton loading libraries.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `vue-loading-skeleton` into a Vue 2 application, showing a `Skeleton` component while data is being fetched and then rendering the actual content. It also uses `SkeletonTheme` to apply a consistent animation style.

<!-- App.vue -->
<template>
  <div id="app">
    <h1>Data Loader Example</h1>
    <SkeletonTheme color="#e6f3fd" highlight="#eef6fd">
      <div class="post-card">
        <template v-if="post.title">
          <h2 class="post-title">{{ post.title }}</h2>
          <p class="post-body">{{ post.body }}</p>
        </template>
        <template v-else>
          <div class="loading-state">
            <Skeleton class="post-title" />
            <Skeleton class="post-body" :count="3" />
          </div>
        </template>
      </div>
    </SkeletonTheme>
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
import { Skeleton, SkeletonTheme } from 'vue-loading-skeleton';

interface Post {
  title: string;
  body: string;
}

export default Vue.extend({
  name: 'App',
  components: {
    Skeleton,
    SkeletonTheme,
  },
  data() {
    return {
      post: {} as Post,
    };
  },
  async created() {
    // Simulate API call
    await new Promise(resolve => setTimeout(resolve, 2000));
    this.post = {
      title: 'My Awesome Blog Post',
      body: 'This is the content of my awesome blog post. It has multiple lines to demonstrate the skeleton loading effect. The quick brown fox jumps over the lazy dog. Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    };
  },
});
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.post-card {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #eee;
  border-radius: 8px;
  text-align: left;
}
.post-title {
  font-size: 2em;
  font-weight: bold;
  margin-bottom: 10px;
}
.post-body {
  font-size: 1.1em;
  line-height: 1.6;
}
.loading-state .post-title {
  height: 2em; /* Ensure skeleton matches expected title height */
}
.loading-state .post-body {
  height: 1.1em; /* Ensure skeleton matches expected line height */
}
</style>

view raw JSON →