Skip to content

api-examples

around 1min
a cover for this article

Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:

md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

Results

Theme Data

{
  "logo": "/favicon.ico",
  "nav": [
    {
      "text": "Blog",
      "link": "/blog.md"
    },
    {
      "text": "Gallery",
      "link": "/gallery.md"
    },
    {
      "text": "Music",
      "link": "/music.md"
    },
    {
      "text": "Cookbook",
      "link": "/cookbook.md"
    },
    {
      "text": "Playground",
      "items": [
        {
          "text": "lyrics-scrolling",
          "link": "/playground/lyrics-scrolling.md"
        }
      ]
    }
  ],
  "outline": [
    1,
    5
  ],
  "sidebar": [
    {
      "text": ""
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/mr7ish"
    }
  ],
  "search": {
    "provider": "local"
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep",
    "cover": "/violet dream.jpg",
    "words": 113,
    "time": 33900,
    "text": "1 min read",
    "_min": 0.565,
    "id": "/home/runner/work/mr7ish.github.io/mr7ish.github.io/site/api-examples.md",
    "fileName": "api-examples"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md",
  "lastUpdated": 1779938489000
}

Page Frontmatter

{
  "outline": "deep",
  "cover": "/violet dream.jpg",
  "words": 113,
  "time": 33900,
  "text": "1 min read",
  "_min": 0.565,
  "id": "/home/runner/work/mr7ish.github.io/mr7ish.github.io/site/api-examples.md",
  "fileName": "api-examples"
}

More

Check out the documentation for the full list of runtime APIs.

Todo Island0%
All
Completed
My List
Nothing todo🥳