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": "/docs/guide/"
    },
    {
      "text": "更多",
      "items": [
        {
          "text": "快速入口",
          "link": "/docs/quick-links/"
        },
        {
          "text": "创业实践",
          "link": "/docs/创业实践/"
        },
        {
          "text": "创业实践dasd",
          "link": "/docs/chuanye/"
        },
        {
          "text": "VitePress 官网",
          "link": "https://vitepress.dev"
        },
        {
          "text": "社区",
          "items": [
            {
              "text": "GitHub",
              "link": "https://github.com/vuejs/vitepress"
            },
            {
              "text": "Discord",
              "link": "https://discord.com/invite/HBherRA"
            }
          ]
        }
      ]
    }
  ],
  "sidebar": {
    "/docs/guide/": [
      {
        "text": "Guide",
        "collapsed": false,
        "items": [
          {
            "text": "Asdhj",
            "link": "/docs/guide/asdhj"
          }
        ],
        "link": "/docs/guide/"
      }
    ],
    "/docs/创业实践/": [
      {
        "text": "创业实践",
        "collapsed": false,
        "items": [
          {
            "text": "1.底层心法与思维模型",
            "collapsed": false,
            "items": [
              {
                "text": "概述",
                "link": "/docs/创业实践/1.底层心法与思维模型/"
              }
            ]
          },
          {
            "text": "2.创业全流程实战(从0到1)",
            "collapsed": false,
            "items": [
              {
                "text": "概述",
                "link": "/docs/创业实践/2.创业全流程实战(从0到1)/"
              }
            ]
          },
          {
            "text": "3.团队与管理",
            "collapsed": false,
            "items": [
              {
                "text": "概述",
                "link": "/docs/创业实践/3.团队与管理/"
              }
            ]
          },
          {
            "text": "4. 资本与融资",
            "collapsed": false,
            "items": [
              {
                "text": "概述",
                "link": "/docs/创业实践/4. 资本与融资/"
              }
            ]
          },
          {
            "text": "5. 传记与公司案例",
            "collapsed": false,
            "items": [
              {
                "text": "概述",
                "link": "/docs/创业实践/5. 传记与公司案例/"
              }
            ]
          },
          {
            "text": "6. 副业、一人企业与小众创业",
            "collapsed": false,
            "items": [
              {
                "text": "概述",
                "link": "/docs/创业实践/6. 副业、一人企业与小众创业/"
              }
            ]
          },
          {
            "text": "7. 中国本土与行业专题",
            "collapsed": false,
            "items": [
              {
                "text": "概述",
                "link": "/docs/创业实践/7. 中国本土与行业专题/"
              }
            ]
          },
          {
            "text": "关于",
            "link": "/docs/创业实践/关于"
          }
        ],
        "link": "/docs/创业实践/"
      }
    ],
    "/docs/chuanye/": [
      {
        "text": "Chuanye",
        "collapsed": false,
        "items": [
          {
            "text": "Sad",
            "link": "/docs/chuanye/sad"
          }
        ],
        "link": "/docs/chuanye/"
      }
    ]
  }
}

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.