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": "/intro/introduction",
      "activeMatch": "/intro/"
    },
    {
      "text": "案例",
      "link": "/use-cases/index",
      "activeMatch": "/use-cases/"
    },
    {
      "text": "手册",
      "link": "/manual/index",
      "activeMatch": "/manual/"
    },
    {
      "text": "定价",
      "link": "/price/index",
      "activeMatch": "/price/"
    },
    {
      "text": "咨询",
      "link": "/contact/contact",
      "activeMatch": "/contact/"
    },
    {
      "text": "更多",
      "items": [
        {
          "text": "更多需求",
          "items": [
            {
              "text": "私有化部署",
              "link": "/special-needs/privatization-deployment/intro"
            },
            {
              "text": "定制需求",
              "link": "/special-needs/requirement-customization/intro"
            }
          ]
        },
        {
          "text": "二次开发",
          "items": [
            {
              "text": "二次开发文档",
              "link": "/third-party/quick-start"
            }
          ]
        }
      ]
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "locales": {
        "zh": {
          "translations": {
            "button": {
              "buttonText": "搜索文档",
              "buttonAriaLabel": "搜索文档"
            },
            "modal": {
              "noResultsText": "无法找到相关结果",
              "resetButtonTitle": "清除查询条件",
              "footer": {
                "selectText": "选择",
                "navigateText": "切换"
              }
            }
          }
        }
      },
      "miniSearch": {
        "options": {},
        "searchOptions": {}
      }
    }
  },
  "sidebar": {
    "/intro/": {
      "base": "/intro/",
      "items": [
        {
          "text": "简介",
          "collapsed": false,
          "items": [
            {
              "text": "功能介绍",
              "link": "introduction"
            }
          ]
        },
        {
          "text": "用户案例",
          "base": "/use-cases/",
          "link": "index"
        },
        {
          "text": "产品定价",
          "base": "/price/",
          "link": "index"
        },
        {
          "text": "使用手册",
          "base": "/manual/",
          "link": "index"
        },
        {
          "text": "联系我们",
          "base": "/contact/",
          "link": "contact"
        },
        {
          "text": "测试用",
          "collapsed": false,
          "items": [
            {
              "text": "api-examples",
              "base": "/",
              "link": "api-examples"
            },
            {
              "text": "markdown-examples",
              "base": "/",
              "link": "markdown-examples"
            }
          ]
        }
      ]
    },
    "/use-cases/": {
      "base": "/use-cases/",
      "items": []
    },
    "/manual/": {
      "base": "/manual/",
      "items": [
        {
          "text": "使用手册",
          "collapsed": false,
          "items": [
            {
              "text": "简介",
              "link": "index"
            },
            {
              "text": "后台管理",
              "link": "manage"
            },
            {
              "text": "智慧大屏",
              "link": "screen"
            },
            {
              "text": "移动端 App",
              "link": "app"
            }
          ]
        }
      ]
    },
    "/contact/": {
      "base": "/contact/",
      "items": [
        {
          "text": "联系我们",
          "collapsed": false,
          "items": [
            {
              "text": "咨询",
              "link": "contact"
            }
          ]
        },
        {
          "text": "关于我们",
          "link": "about-us"
        }
      ]
    },
    "/special-needs/": {
      "base": "/special-needs/",
      "items": [
        {
          "text": "私有化部署",
          "collapsed": false,
          "base": "/special-needs/privatization-deployment/",
          "items": [
            {
              "text": "私有化部署",
              "link": "intro"
            }
          ]
        },
        {
          "text": "定制需求",
          "collapsed": false,
          "base": "/special-needs/requirement-customization/",
          "items": [
            {
              "text": "流程简介",
              "link": "intro"
            },
            {
              "text": "定制需求",
              "link": "customize"
            }
          ]
        },
        {
          "text": "二次开发",
          "base": "/third-party/",
          "link": "quick-start"
        }
      ]
    },
    "/third-party/": {
      "base": "/third-party/",
      "items": [
        {
          "text": "二次开发",
          "collapsed": false,
          "items": [
            {
              "text": "快速开始",
              "link": "quick-start"
            }
          ]
        },
        {
          "text": "对接文档",
          "link": "third-party"
        }
      ]
    }
  },
  "footer": {
    "copyright": "Copyright © 2023-present 武汉脚印猫科技有限公司"
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "outline": {
    "label": "页面导航",
    "level": [
      2,
      4
    ]
  },
  "langMenuLabel": "多语言",
  "returnToTopLabel": "回到顶部",
  "sidebarMenuLabel": "菜单",
  "darkModeSwitchLabel": "主题",
  "lightModeSwitchTitle": "切换到浅色模式",
  "darkModeSwitchTitle": "切换到深色模式"
}

Page Data

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

Page Frontmatter

{
  "outline": "deep",
  "pagefind-indexed": false
}

More

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