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

{
  "i18nRouting": false,
  "search": {
    "provider": "local"
  },
  "logo": "/logo.svg",
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "项目介绍",
      "items": [
        {
          "text": "简介",
          "link": "/md/introduction/"
        },
        {
          "text": "介绍1",
          "link": "/md/introduction/i1"
        },
        {
          "text": "介绍2",
          "link": "/md/introduction/i2"
        }
      ]
    },
    {
      "text": "使用文档",
      "link": "/md/documentation/"
    },
    {
      "text": "关于我",
      "items": [
        {
          "text": "Github",
          "link": "https://github.com/xoxosos"
        },
        {
          "text": "博客园",
          "link": "https://www.cnblogs.com/pglin/"
        }
      ]
    }
  ],
  "sidebar": {
    "/md/introduction/": [
      {
        "text": "简介",
        "link": "/md/introduction/"
      },
      {
        "text": "介绍1",
        "items": [
          {
            "text": "介绍1-1",
            "link": "/md/introduction/i1"
          }
        ]
      },
      {
        "text": "介绍2",
        "items": [
          {
            "text": "介绍2-2",
            "link": "/md/introduction/i2"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/xoxosos/vue-ace-admin"
    }
  ]
}

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.