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

{
  "outlineTitle": "文章目录",
  "outline": [
    2,
    6
  ],
  "logo": "/logo.svg",
  "search": {
    "provider": "local",
    "options": {
      "button": {
        "buttonText": "搜索文档",
        "buttonAriaLabel": "搜索文档"
      },
      "modal": {
        "noResultsText": "无法找到相关结果",
        "resetButtonTitle": "清除查询条件",
        "footer": {
          "selectText": "选择",
          "navigateText": "切换"
        }
      }
    }
  },
  "footer": {
    "copyright": "Copyright@ 2024 LLLLM"
  },
  "nav": [
    {
      "text": "工具",
      "items": [
        {
          "text": "首页",
          "link": "/"
        },
        {
          "text": "中文技术文档的写作规范",
          "link": "/tool/docs/marks"
        }
      ]
    },
    {
      "text": "实例",
      "link": "/markdown-examples"
    }
  ],
  "sidebar": [
    {
      "text": "中文技术文档的写作规范",
      "items": [
        {
          "text": "标点符号",
          "link": "/tool/docs/marks"
        },
        {
          "text": "数值",
          "link": "/tool/docs/number"
        },
        {
          "text": "段落",
          "link": "/tool/docs/paragraph"
        },
        {
          "text": "标题",
          "link": "/tool/docs/title"
        },
        {
          "text": "文档体系",
          "link": "/tool/docs/structure"
        },
        {
          "text": "参考链接",
          "link": "/tool/docs/reference"
        },
        {
          "text": "文本",
          "link": "/tool/docs/text"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/LLLLM01"
    }
  ]
}

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.