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

{
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "无人机",
      "link": "/guide/fly_with_optical_flow"
    },
    {
      "text": "示例",
      "link": "/markdown-examples"
    }
  ],
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "footer": {
    "message": "<a href=\"https://beian.miit.gov.cn\">湘ICP备2023024374号-1</a>",
    "copyright": "版权所有 © 2025-至今 趣玩极客"
  },
  "outline": {
    "label": "页面导航"
  },
  "sidebar": {
    "/guide/": [
      {
        "text": "基础入门",
        "collapsed": false,
        "items": [
          {
            "text": "【基础编程】无人机介绍",
            "link": "/guide/drone_intro"
          },
          {
            "text": "【基础编程】光流定位绕杆飞行",
            "link": "/guide/fly_with_optical_flow"
          },
          {
            "text": "【基础编程】标签定位绕杆飞行",
            "link": "/guide/fly_with_tag"
          },
          {
            "text": "【基础编程】正弦环绕绕杆飞行",
            "link": "/guide/fly_sine_around_ring"
          },
          {
            "text": "【基础编程】沿着黑线飞行",
            "link": "/guide/fly_follow_line"
          },
          {
            "text": "【基础编程】标签定位穿越圆环",
            "link": "/guide/fly_cross_circle"
          },
          {
            "text": "【基础编程】使用坐标系飞行",
            "link": "/guide/fly_using_a_coordinate_system"
          }
        ]
      }
    ],
    "/": [
      {
        "text": "Examples",
        "items": [
          {
            "text": "Markdown Examples",
            "link": "/markdown-examples"
          },
          {
            "text": "Runtime API Examples",
            "link": "/api-examples"
          }
        ]
      }
    ]
  },
  "socialLinks": []
}

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.