Getting Started
Quick Start
Your first skeleton in a minute.
The examples use Nuxt's
useFetch. In Vue, pass a TanStack Query result to :of instead, as shown in Vue + Vite.Load the data on the client
A skeleton is only needed while the data isn't there yet, so the request shouldn't hold up the server:
const posts = useFetch<Post[]>('/api/posts', { lazy: true, server: false })
Describe a sample
The sample mirrors the shape of the response, with text of about the real length. It draws the shape on the first visit:
const sample: Post[] = [{ id: 1, title: 'A title of about this length' }]
Wrap your markup
<Skeleton :of="posts" :sample>
<template #default="{ data }">
<PostCard v-for="post in data" :key="post.id" :post />
</template>
</Skeleton>
data in the slot is typed from useFetch, so a typo in a field is a compile error.
The result
A real request to DummyJSON, delayed by 1.2 seconds:
<script setup lang="ts">
const posts = useFetch<Posts>('https://dummyjson.com/posts?limit=3&delay=1200', {
lazy: true,
server: false,
})
const sample: Posts = {
posts: [{ id: 1, title: 'A post title of about this length', reactions: { likes: 100 } }],
}
</script>
<template>
<Skeleton :of="posts" :sample>
<template #default="{ data }">
<ul>
<li v-for="post in data.posts" :key="post.id">
{{ post.title }}
<UBadge :label="`${post.reactions.likes} likes`" />
</li>
</ul>
</template>
</Skeleton>
</template>