Skip to content
On this page

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

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Blogs",
      "link": "/Talk about谈论"
    }
  ],
  "sidebar": [
    {
      "text": "Blogs",
      "items": [
        {
          "text": "Science and Technology IELTS Sample Essay",
          "link": "/Science and Technology IELTS Sample Essay"
        },
        {
          "text": "Talk about谈论",
          "link": "/Talk about谈论"
        },
        {
          "text": "Vue八股文",
          "link": "/Vue八股文"
        },
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        },
        {
          "text": "React-Hooks",
          "link": "/React-Hooks"
        },
        {
          "text": "妙语",
          "link": "/妙语"
        },
        {
          "text": "骑电驴记",
          "link": "/骑电驴记"
        },
        {
          "text": "问题讨论与人交际",
          "link": "/问题讨论与人交际"
        },
        {
          "text": "遐想",
          "link": "/遐想"
        },
        {
          "text": "自习室学习记",
          "link": "/自习室学习记"
        },
        {
          "text": "小米创业启示录已阅",
          "link": "/小米创业启示录已阅"
        },
        {
          "text": "2021重新出发",
          "link": "/2021重新出发"
        },
        {
          "text": "关于博客",
          "link": "/关于博客"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://gitee.com/run_yu163"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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