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

{
  "search": {
    "provider": "local"
  },
  "outline": "deep",
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "相关阅读",
      "items": [
        {
          "text": "运维",
          "link": "/KnowledgeBase/运维/django-docker"
        },
        {
          "text": "UI",
          "link": "/KnowledgeBase/UI/miev-nav"
        },
        {
          "text": "Apple ID 美区注册",
          "link": "/KnowledgeBase/AppleID美区注册"
        },
        {
          "text": "安卓TK",
          "link": "/KnowledgeBase/一些工具/tiktok-mod"
        },
        {
          "text": "Telegram安卓苹果登录注册以及相关设置",
          "link": "/vpn/telegram"
        },
        {
          "text": "Facebook防封养号相关设置",
          "link": "/vpn/facebook"
        },
        {
          "text": "使用身份验证器(Authenticator)开启 Facebook 双重验证(2FA)",
          "link": "/KnowledgeBase/一些工具/Authenticatorfor2FA"
        }
      ]
    },
    {
      "text": "浅谈浅见",
      "items": [
        {
          "text": "看山是山",
          "link": "/CasualTalk/看山是山"
        }
      ]
    },
    {
      "text": "技术服务",
      "items": [
        {
          "text": "业务介绍",
          "link": "/about/business"
        },
        {
          "text": "Hws文件富搜索",
          "link": "/utility/everything-voidtools"
        }
      ]
    }
  ],
  "sidebar": {
    "/Examples/": [
      {
        "text": "api-examples",
        "link": "/Examples/api-examples"
      },
      {
        "text": "markdown-examples",
        "link": "/Examples/markdown-examples"
      }
    ],
    "/KnowledgeBase/运维/": [
      {
        "text": "CICD Vitepress gitactions stiemap",
        "link": "/KnowledgeBase/运维/CICD"
      },
      {
        "text": "Django 使用gitaction构建 dokcer镜像, 并发布到github, dockerhub, 阿里云镜像",
        "link": "/KnowledgeBase/运维/django-docker"
      },
      {
        "text": "Ubuntu partition 扩展分区",
        "link": "/KnowledgeBase/运维/ubuntu-partition"
      },
      {
        "text": "video-test",
        "link": "/KnowledgeBase/运维/video-test"
      },
      {
        "text": "记一次 VitePress 博客\"最近更新\"排序失效的完整调试过程",
        "link": "/KnowledgeBase/运维/vitepress-posts-sort-debug"
      }
    ],
    "/KnowledgeBase/UI/": [
      {
        "text": "仿小米汽车网站导航",
        "link": "/KnowledgeBase/UI/miev-nav"
      }
    ],
    "/CasualTalk/": [
      {
        "text": "看山是山",
        "link": "/CasualTalk/看山是山"
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/WorshipMoon/sean_web"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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