Skip to content

Runtime API Examples123

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

{
  "sidebar": [
    {
      "text": "简介",
      "link": "/introduction"
    },
    {
      "text": "快速开始",
      "link": "/quickstart"
    },
    {
      "text": "功能目录",
      "link": "/catalogue"
    },
    {
      "text": "配置",
      "link": "/configuration",
      "items": [
        {
          "text": "Web 配置",
          "link": "/configuration/web"
        }
      ]
    },
    {
      "text": "基础功能 ",
      "link": "/basic-feature",
      "items": [
        {
          "text": "常量定义",
          "collapsed": true,
          "items": [
            {
              "text": "基础框架",
              "link": "/feature/constant/KrismileConstant"
            },
            {
              "text": "正则表达式",
              "link": "/feature/constant/PatternConstantRegex"
            },
            {
              "text": "日期格式",
              "link": "/feature/constant/PatternConstantDate"
            },
            {
              "text": "日志Key",
              "link": "/feature/constant/LogKey"
            }
          ]
        },
        {
          "text": "枚举定义",
          "link": "/feature/enumeration/index"
        },
        {
          "text": "异常处理",
          "link": "/feature/error/index",
          "collapsed": true,
          "items": [
            {
              "text": "控制器异常处理",
              "link": "/feature/error/controller"
            }
          ]
        },
        {
          "text": "日志组件",
          "link": "/feature/logging/index"
        },
        {
          "text": "执行器",
          "link": "/feature/executor/index"
        },
        {
          "text": "控制器",
          "link": "/feature/controller/index"
        },
        {
          "text": "日期处理",
          "link": "/feature/date/index"
        }
      ]
    },
    {
      "text": "高级功能 ",
      "link": "/advanced-feature",
      "items": [
        {
          "text": "请求日志",
          "link": "/feature/aspect/requestlog"
        },
        {
          "text": "参数检查",
          "link": "/feature/aspect/checkparam"
        },
        {
          "text": "跨域处理",
          "link": "/feature/filter/cors"
        },
        {
          "text": "请求体处理",
          "link": "/feature/filter/requestbody"
        }
      ]
    },
    {
      "text": "Mybatis Plus",
      "items": [
        {
          "text": "快速开始",
          "link": "/mybatisplus/quickstart"
        },
        {
          "text": "基础实体类",
          "link": "/mybatisplus/entity"
        },
        {
          "text": "增强 Service 层",
          "link": "/mybatisplus/service"
        },
        {
          "text": "校验与检查",
          "link": "/mybatisplus/validation"
        },
        {
          "text": "自动填充",
          "link": "/mybatisplus/autofill"
        }
      ]
    },
    {
      "text": "其他",
      "items": [
        {
          "text": "IntelliJ IDEA",
          "link": "/idea/index"
        }
      ]
    }
  ],
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "i18nRouting": true,
  "logo": "/logo-mini.png",
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/krismileji"
    },
    {
      "icon": "gitee",
      "link": "https://gitee.com/krismileJ"
    }
  ],
  "footer": {
    "message": "Released under the Apache-2.0 License",
    "copyright": "Copyright © 2021-2025 krismile"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the Apache-2.0 License