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": "/favicon.svg",
  "search": {
    "provider": "local"
  },
  "lastUpdated": {
    "text": "Updated at",
    "formatOptions": {
      "dateStyle": "full",
      "timeStyle": "medium"
    }
  },
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "文档",
      "link": "/docs/docs"
    },
    {
      "text": "工具",
      "link": "/tools/tools"
    }
  ],
  "sidebar": {
    "/docs/": [
      {
        "text": "Docs",
        "items": [
          {
            "text": "EMQX",
            "link": "/docs/MQTT"
          },
          {
            "text": "VitePress 使用教程",
            "link": "/docs/docs"
          },
          {
            "text": "泛型函数",
            "link": "/docs/harmonyNextUI"
          },
          {
            "text": "LaTeX 的书写技巧",
            "link": "/docs/latex"
          },
          {
            "text": "LaTeX `.cls` 文件编写经验",
            "link": "/docs/latexcls"
          },
          {
            "text": "latexfcls",
            "link": "/docs/latexfcls"
          },
          {
            "text": "latexofcls",
            "link": "/docs/latexofcls"
          },
          {
            "text": "linuxnew",
            "link": "/docs/linuxnew"
          },
          {
            "text": "nginx 配置",
            "link": "/docs/nginx"
          },
          {
            "text": "OpenHarmony SDK编译手册 ",
            "link": "/docs/openharmony"
          },
          {
            "text": "shell命令",
            "link": "/docs/shell"
          },
          {
            "text": "ubuntu根目录编译",
            "link": "/docs/ubuntu根目录编译"
          }
        ]
      }
    ],
    "/tools/": [
      {
        "text": "Tools",
        "items": [
          {
            "text": "test",
            "link": "/tools/test"
          },
          {
            "text": "常用软件",
            "link": "/tools/tools"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/JuckyLee668"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Updated at: