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": "/logo-icon.png",
  "lastUpdated": {
    "text": "最后更新于",
    "formatOptions": {
      "dateStyle": "full",
      "timeStyle": "medium"
    }
  },
  "outline": {
    "level": [
      2,
      6
    ],
    "label": "页面导航"
  },
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "noResultsText": "无法找到相关结果",
          "resetButtonTitle": "清除查询条件",
          "displayDetails": "展示详细列表",
          "footer": {
            "selectText": "选择",
            "navigateText": "切换",
            "closeText": "关闭"
          }
        }
      }
    }
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "前端",
      "link": "/front/guide/page.md"
    },
    {
      "text": "后端",
      "link": "/backend/guide/preface.md"
    },
    {
      "text": "链接",
      "items": [
        {
          "text": "github",
          "link": "https://github.com/lw123lw/threebird-doc"
        },
        {
          "text": "gitee",
          "link": "https://github.com/lw123lw/threebird-doc"
        }
      ]
    }
  ],
  "sidebar": {
    "/front": [
      {
        "text": "开发指南",
        "collapsed": false,
        "items": [
          {
            "text": "什么是ThreeBird Admin",
            "link": "/front/guide/page.md"
          },
          {
            "text": "开始使用",
            "link": "/front/guide/start.md"
          },
          {
            "text": "Q&A",
            "link": "/front/guide/qa.md"
          }
        ]
      },
      {
        "text": "组件示例",
        "collapsed": false,
        "items": [
          {
            "text": "proTable(超级表格)",
            "link": "/front/components/proTable.md"
          },
          {
            "text": "proForm(超级表单)",
            "link": "/front/components/proForm.md"
          }
        ]
      }
    ],
    "/backend": [
      {
        "text": "指南",
        "collapsed": false,
        "items": [
          {
            "text": "前言",
            "link": "/backend/guide/preface.md"
          },
          {
            "text": "快速上手",
            "link": "/backend/guide/quickStart.md"
          }
        ]
      },
      {
        "text": "开发规范",
        "collapsed": false,
        "items": [
          {
            "text": "提交规范",
            "link": "/backend/standard/submitStandard.md"
          },
          {
            "text": "代码规范",
            "link": "/backend/standard/codeStandard.md"
          }
        ]
      },
      {
        "text": "平台组件",
        "collapsed": false,
        "items": [
          {
            "text": "核心组件",
            "link": "/backend/platform/one.md"
          }
        ]
      },
      {
        "text": "业务模块",
        "collapsed": false,
        "items": [
          {
            "text": "test",
            "link": "/backend/business/one.md"
          }
        ]
      },
      {
        "text": "常见问题",
        "collapsed": false,
        "items": [
          {
            "text": "版本依赖",
            "link": "/backend/question/one.md"
          }
        ]
      },
      {
        "text": "更新日志",
        "collapsed": false,
        "items": [
          {
            "text": "v1.01",
            "link": "/backend/changelog/2024/one.md"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ],
  "footer": {
    "copyright": "Copyright © 2024-ThreeBird Admin"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

最后更新于: