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

{
  "siteTitle": "知识库",
  "logo": "/logo.svg",
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "前端",
      "items": [
        {
          "text": "Vue3源码",
          "link": "/docs/frontend/vue3-core/docs/index.md"
        },
        {
          "text": "资源文件",
          "link": "/docs/frontend/resource/table-pro/index.md"
        }
      ]
    }
  ],
  "sidebar": {
    "/docs/frontend/vue3-core/": [
      {
        "items": [
          {
            "text": "Vue3源码",
            "link": "/docs/frontend/vue3-core/docs/index.md"
          }
        ]
      }
    ],
    "/docs/frontend/resource/": [
      {
        "items": [
          {
            "text": "开发技巧",
            "link": "/docs/frontend/resource/development-skills/index.md"
          },
          {
            "text": "table-pro",
            "link": "/docs/frontend/resource/table-pro/index.md"
          },
          {
            "text": "命令式弹窗",
            "link": "/docs/frontend/resource/Imperative-popup/index.md"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/JINL000/JINL000.github.io"
    }
  ],
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "lastUpdated": {
    "text": "最后更改时间",
    "formatOptions": {
      "dateStyle": "full",
      "timeStyle": "short"
    }
  },
  "search": {
    "provider": "local"
  },
  "outline": {
    "label": "本页目录"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

最后更改时间: