Skip to content

v-skeleton

Skeleton loading placeholder.

Since: 1.5.0

Usage

Basic

vue
<template>
  <div v-skeleton="isLoading">Content here</div>
</template>

<script setup>
import { ref } from 'vue'

const isLoading = ref(true)
</script>

With Options

vue
<template>
  <div v-skeleton="{
    loading: isLoading,
    animation: 'pulse',
    width: 200,
    height: 20
  }">
    Content here
  </div>
</template>

API

Options

OptionTypeDefaultDescription
loadingbooleantrueWhether to show skeleton
animation'wave' | 'pulse' | 'none''wave'Animation type
widthnumber | string'100%'Skeleton width
heightnumber | string'auto'Skeleton height
colorstring'#e8e8e8'Skeleton color
radiusnumber | string'4px'Border radius
rowsnumber1Number of skeleton rows
rowGapnumber | string'12px'Gap between rows

Binding Types

ts
type SkeletonBinding = boolean | SkeletonOptions

Examples

Card Skeleton

vue
<template>
  <div class="card" v-skeleton="isLoading">
    <h3>Title</h3>
    <p>Description text here...</p>
    <button>Action</button>
  </div>
</template>

<style>
.card {
  padding: 16px;
  border-radius: 8px;
  background: white;
}
</style>

Multiple Rows

vue
<template>
  <div v-skeleton="{
    loading: isLoading,
    rows: 3,
    rowGap: '8px',
    animation: 'pulse'
  }">
    <p>Line 1</p>
    <p>Line 2</p>
    <p>Line 3</p>
  </div>
</template>

List Skeleton

vue
<template>
  <div v-for="item in items" :key="item.id" v-skeleton="isLoading">
    {{ item.name }}
  </div>
</template>

Composable API

For programmatic use, you can use the useSkeleton composable:

typescript
import { useSkeleton } from 'directix'

const { show, hide, update, isLoading } = useSkeleton({
  animation: 'wave',
  color: '#e8e8e8'
})

// Show skeleton
show()

// Hide skeleton
hide()

// Update options
update({ animation: 'pulse' })

UseSkeletonReturn

PropertyTypeDescription
show() => voidShow skeleton
hide() => voidHide skeleton
update(options: Partial<SkeletonOptions>) => voidUpdate options
isLoadingRef<boolean>Current loading state

Code Generator

Quick Code Generator
<template>
  <div v-skeleton="{ loading: true, animation: 'wave' }">
    <!-- Skeleton loading placeholder. directive -->
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// Configure your options here
const options = { loading: true, animation: 'wave' }
</script>

Released under the MIT License.