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": "/docs/airport-recommend"
    },
    {
      "text": "软件下载",
      "link": "/docs/software-download"
    },
    {
      "text": "小火箭账号",
      "link": "/docs/free-rocket-account"
    },
    {
      "text": "实用教程",
      "link": "/docs/tutorials"
    }
  ],
  "sidebar": {
    "/docs/": [
      {
        "text": "机场推荐",
        "items": [
          {
            "text": "推荐机场",
            "link": "/docs/airport-recommend"
          }
        ]
      },
      {
        "text": "软件下载",
        "items": [
          {
            "text": "下载中心",
            "link": "/docs/software-download"
          }
        ]
      },
      {
        "text": "免费资源",
        "items": [
          {
            "text": "免费小火箭账号",
            "link": "/docs/free-rocket-account"
          }
        ]
      },
      {
        "text": "实用教程",
        "items": [
          {
            "text": "使用指南",
            "link": "/docs/tutorials"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com"
    }
  ],
  "footer": {
    "message": "机场妹妹 - 让网络更自由",
    "copyright": "Copyright © 2024 机场妹妹"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Last updated:

机场妹妹 - 让网络更自由