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": "最后更新于:",
    "formatOptions": {
      "dateStyle": "full",
      "timeStyle": "medium"
    }
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Document",
      "link": "/document/"
    },
    {
      "text": "Interview",
      "link": "/interview/"
    },
    {
      "text": "Blog",
      "link": "/blog/2025-02-05-本地部署deepseek"
    },
    {
      "text": "awesome",
      "link": "/awesome/"
    }
  ],
  "sidebar": {
    "/document/": [
      {
        "text": "Document",
        "base": "/document",
        "link": "/",
        "items": [
          {
            "text": "Git",
            "link": "/git"
          },
          {
            "text": "Docker",
            "base": "/document/docker",
            "items": [
              {
                "text": "Docker快速部署容器",
                "link": "/docker快速部署容器"
              },
              {
                "text": "Docker实例",
                "base": "/document/docker",
                "items": [
                  {
                    "text": "Docker Redis",
                    "link": "/docker-redis"
                  }
                ]
              }
            ]
          },
          {
            "text": "Typescript",
            "link": "/typescript"
          },
          {
            "text": "数学",
            "link": "/数学"
          }
        ]
      }
    ],
    "/interview/": [
      {
        "text": "Interview",
        "base": "/interview",
        "link": "/",
        "items": [
          {
            "text": "TCP粘包",
            "link": "/TCP粘包"
          }
        ]
      }
    ],
    "/blog/": [
      {
        "text": "Blog",
        "base": "/blog",
        "items": [
          {
            "text": "本地部署deepseek",
            "link": "/2025-02-05-本地部署deepseek"
          },
          {
            "text": "hadoop",
            "link": "/2024-08-23-hadoop"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

最后更新于::