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": "/markdown-examples"
    }
  ],
  "sidebar": [
    {
      "text": "📅 近期聚焦",
      "collapsed": false,
      "items": [
        {
          "text": "Schedule",
          "link": "/Schedule_Howard"
        },
        {
          "text": "Tips",
          "link": "/tips"
        }
      ]
    },
    {
      "text": "🎓 学术与课程",
      "collapsed": false,
      "items": [
        {
          "text": "统计学习理论",
          "link": "/StatisticalLearningTheory"
        },
        {
          "text": "神经网络优化算法",
          "link": "/神经网络优化算法模型"
        },
        {
          "text": "机器学习课程",
          "link": "/机器学习与数据挖掘课程论文"
        },
        {
          "text": "毕业课题选择",
          "link": "/毕业课题 选择"
        },
        {
          "text": "正大杯项目",
          "link": "/正大杯"
        }
      ]
    },
    {
      "text": "🧩 随笔与测试",
      "collapsed": true,
      "items": [
        {
          "text": "技术 Tips",
          "link": "/tips"
        },
        {
          "text": "API 示例",
          "link": "/api-examples"
        },
        {
          "text": "Markdown 示例",
          "link": "/markdown-examples"
        },
        {
          "text": "测试页面",
          "link": "/这是一个测试"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/Goudabaooo/My-Notes"
    }
  ]
}

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.