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

{
  "logo": "https://avatars.githubusercontent.com/u/169712528",
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/1224HuangJin/Vitepress-Template"
    },
    {
      "icon": "discord",
      "link": "https://discord.com/app"
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "locales": {
        "root": {
          "translations": {
            "button": {
              "buttonText": "搜索",
              "buttonAriaLabel": "搜索"
            },
            "modal": {
              "displayDetails": "显示详细列表",
              "resetButtonTitle": "重置搜索",
              "backButtonTitle": "关闭搜索",
              "noResultsText": "没有结果",
              "footer": {
                "selectText": "选择",
                "selectKeyAriaLabel": "输入",
                "navigateText": "导航",
                "navigateUpKeyAriaLabel": "上箭头",
                "navigateDownKeyAriaLabel": "下箭头",
                "closeText": "关闭",
                "closeKeyAriaLabel": "Esc"
              }
            }
          }
        }
      }
    }
  },
  "editLink": {
    "pattern": "https://github.com/1224HuangJin/Vitepress-Template/edit/main/:path",
    "text": "Edit this page on GitHub"
  },
  "lastUpdated": {
    "text": "Last update at",
    "formatOptions": {
      "dateStyle": "full",
      "timeStyle": "medium",
      "forceLocale": true
    }
  },
  "nav": [
    {
      "text": "Home",
      "link": "/en/"
    },
    {
      "text": "MarkDown Examples",
      "link": "/en/markdown-examples"
    },
    {
      "text": "API Examples",
      "link": "/en/api-examples"
    }
  ],
  "sidebar": [
    {
      "text": "Sidebar 1",
      "items": [
        {
          "text": "API Exemples",
          "link": "/en/api-examples"
        }
      ]
    },
    {
      "text": "Sidebar 2",
      "items": [
        {
          "text": "MarkDown Exemples",
          "link": "/en/markdown-examples"
        }
      ]
    }
  ],
  "footer": {
    "message": "All content on this website released under ... license",
    "copyright": "Copyright © 2026 1224HuangJin"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

All content on this website released under ... license