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

{
  "logo": "/favicon.ico",
  "outline": {
    "level": [
      1,
      3
    ]
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "快速开始",
      "link": "/quick-start/quick-start"
    },
    {
      "text": "下载",
      "link": "/function/download"
    }
  ],
  "sidebar": [
    {
      "text": "联机_快速开始",
      "collapsed": true,
      "items": [
        {
          "text": "快速联机",
          "link": "/quick-start/quick-start"
        },
        {
          "text": "常见问题",
          "link": "/quick-start/normalquesion"
        },
        {
          "text": "获取支持",
          "link": "/quick-start/gethelp"
        }
      ]
    },
    {
      "text": "MCTLogServer日志收集",
      "collapsed": true,
      "items": [
        {
          "text": "Readme.md",
          "link": "/function/logcollege"
        },
        {
          "text": "Config配置说明",
          "link": "/function/logconfig"
        },
        {
          "text": "Example(C#)",
          "link": "/example/logexample"
        }
      ]
    },
    {
      "text": "MCTRoomList",
      "collapsed": true,
      "items": [
        {
          "text": "Build for Production",
          "link": "/quick-start/quick-start#build-for-production"
        },
        {
          "text": "GitHub Pages",
          "link": "/quick-start/quick-start#deploy-to-github-pages"
        },
        {
          "text": "Netlify",
          "link": "/quick-start/quick-start#netlify-deployment"
        }
      ]
    },
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/examples/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/examples/api-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/linfon18/mctdocx"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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