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": {
    "src": "/favicon.ico",
    "width": 24,
    "height": 24
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "开发规范",
      "items": [
        {
          "text": "Java开发规范",
          "link": "/java/编程规约/命名风格"
        },
        {
          "text": ".Net开发规范",
          "link": "/dotnet/编程规约"
        }
      ]
    },
    {
      "text": "产品手册",
      "items": [
        {
          "text": "代码生成器",
          "link": "/guide/代码生成器"
        }
      ]
    },
    {
      "text": "dotnet相关",
      "items": [
        {
          "text": "单元测试覆盖率报告",
          "link": "/dotnet/other/单元测试覆盖率报告.md"
        }
      ]
    }
  ],
  "search": {
    "provider": "local"
  },
  "editLink": {
    "pattern": "https://git.yunbaitech.cn/base/yunbai.tech.doc/edit/main/docs/:path",
    "text": "在 GitLab 上编辑此页面"
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "outline": {
    "label": "页面导航"
  },
  "lastUpdated": {
    "text": "最后更新于",
    "formatOptions": {
      "dateStyle": "short",
      "timeStyle": "medium"
    }
  },
  "langMenuLabel": "多语言",
  "returnToTopLabel": "回到顶部",
  "sidebarMenuLabel": "菜单",
  "darkModeSwitchLabel": "主题",
  "lightModeSwitchTitle": "切换到浅色模式",
  "darkModeSwitchTitle": "切换到深色模式",
  "sidebar": {
    "/java/": {
      "base": "/java/",
      "items": [
        {
          "text": "一、编程规约",
          "collapsed": false,
          "items": [
            {
              "text": "(一)命名风格",
              "link": "编程规约/命名风格"
            },
            {
              "text": "(二)常量定义",
              "link": "编程规约/常量定义"
            },
            {
              "text": "(三)代码格式",
              "link": "编程规约/代码格式"
            },
            {
              "text": "(四)OOP规范",
              "link": "编程规约/OOP规范"
            },
            {
              "text": "(五)集合处理",
              "link": "编程规约/集合处理"
            },
            {
              "text": "(六)并发处理",
              "link": "编程规约/并发处理"
            },
            {
              "text": "(七)控制语句",
              "link": "编程规约/控制语句"
            },
            {
              "text": "(八)注释规约",
              "link": "编程规约/注释规约"
            }
          ]
        },
        {
          "text": "二、异常日志",
          "collapsed": true,
          "items": [
            {
              "text": "(一)异常处理",
              "link": "异常日志/异常处理"
            },
            {
              "text": "(二)日志规范",
              "link": "异常日志/日志规约"
            },
            {
              "text": "(三)其他",
              "link": "异常日志/其他"
            }
          ]
        },
        {
          "text": "三、单元测试",
          "link": "单元测试"
        },
        {
          "text": "四、安全规约",
          "link": "安全规约"
        },
        {
          "text": "五、MySQL数据库",
          "collapsed": true,
          "items": [
            {
              "text": "(一)建表规约",
              "link": "MySQL数据库/建表规约"
            },
            {
              "text": "(二)索引规约",
              "link": "MySQL数据库/索引规约"
            },
            {
              "text": "(三)SQL语句",
              "link": "MySQL数据库/SQL语句"
            },
            {
              "text": "(四)ORM映射",
              "link": "MySQL数据库/ORM映射"
            }
          ]
        },
        {
          "text": "六、工程结构",
          "collapsed": true,
          "items": [
            {
              "text": "(一)应用分层",
              "link": "工程结构/应用分层"
            },
            {
              "text": "(二)二方库依赖",
              "link": "工程结构/二方库依赖"
            },
            {
              "text": "(三)服务器",
              "link": "工程结构/服务器"
            }
          ]
        },
        {
          "text": "附:本手册专有名词",
          "link": "本手册专有名词"
        }
      ]
    },
    "/dotnet/": [
      {
        "text": "规约",
        "items": [
          {
            "text": "编程规约",
            "link": "/dotnet/编程规约.md"
          },
          {
            "text": "设计规约",
            "link": "/dotnet/设计规约.md"
          }
        ]
      },
      {
        "text": "其他",
        "items": [
          {
            "text": "单元测试覆盖率报告",
            "link": "/dotnet/other/单元测试覆盖率报告.md"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://git.yunbaitech.cn/base/yunbai.tech.doc.git"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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