Skip to content
TablesAreCool
col 3 isright-aligned$1600
col 2 iscentered$12
zebra stripesare neat$1

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: An image

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

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Examples",
      "link": "/markdown-examples"
    },
    {
      "text": "Dropdown Menu",
      "items": [
        {
          "text": "Item A",
          "link": "/item-1"
        },
        {
          "text": "Item B",
          "items": [
            {
              "text": "Section A Item A",
              "link": "..."
            },
            {
              "text": "Section B Item B",
              "link": "..."
            }
          ]
        },
        {
          "text": "Item C",
          "link": "/item-3"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "aside": true,
  "outline": {
    "level": 2,
    "label": "Config Outline Text"
  },
  "socialLinks": [
    {
      "icon": "discord",
      "link": "https://discord.gg/JYuyHaQ"
    },
    {
      "icon": "github",
      "link": "https://github.com/Azperin/"
    }
  ]
}

Page Data

{
  "title": "Zzzzzzzzzzzzzz",
  "description": "",
  "frontmatter": {
    "layout": "doc",
    "outline": "deep",
    "title": "Zzzzzzzzzzzzzz",
    "navbar": true,
    "sidebar": true,
    "aside": true,
    "footer": false
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md"
}

Page Frontmatter

{
  "layout": "doc",
  "outline": "deep",
  "title": "Zzzzzzzzzzzzzz",
  "navbar": true,
  "sidebar": true,
  "aside": true,
  "footer": false
}

More

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