Skip to content

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

{
  "lastUpdated": {
    "text": "Updated at",
    "formatOptions": {
      "dateStyle": "full",
      "timeStyle": "medium"
    }
  },
  "nav": [
    {
      "text": "Home",
      "link": "https://lzzs.fun"
    },
    {
      "text": "Blog",
      "link": "https://lzzs.fun/blog"
    },
    {
      "text": "Dropdown Menu",
      "items": [
        {
          "text": "Item A1",
          "items": [
            {
              "text": "Section A Item A",
              "link": "/item-3"
            }
          ]
        },
        {
          "text": "Item B",
          "link": "/item-3"
        },
        {
          "text": "Item C",
          "link": "/item-3"
        }
      ]
    }
  ],
  "logo": "/favicon.svg",
  "footer": {
    "copyright": "Copyright © 2024-present Lzz"
  },
  "sidebar": [
    {
      "text": "CS 000",
      "items": [
        {
          "text": "首页",
          "link": "/"
        },
        {
          "text": "Markdown Examples1",
          "link": "https://lzzs.fun"
        },
        {
          "text": "Markdown Examples2",
          "link": "/markdown/md"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    },
    {
      "text": "Examples1",
      "items": [
        {
          "text": "Markdown Examples1",
          "link": "/md1"
        },
        {
          "text": "Markdown Examples2",
          "link": "/markdown-examples3"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples3"
        }
      ]
    },
    {
      "text": "Examples2",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples2"
        },
        {
          "text": "Runtime API Examples",
          "items": [
            {
              "text": "Markdown Examples",
              "items": [
                {
                  "text": "Markdown Examples1",
                  "link": "/markdown-examples"
                },
                {
                  "text": "Runtime API Examples",
                  "link": "/api-examples"
                }
              ]
            },
            {
              "text": "Runtime API Examples",
              "link": "/api-examples1"
            }
          ]
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/lzzsG/VitePress-template"
    }
  ],
  "search": {
    "provider": "local"
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md",
  "lastUpdated": 1734422335000
}

Page Frontmatter

{
  "outline": "deep"
}

More

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