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": "/guide/"
    },
    {
      "text": "数据结构与算法",
      "items": [
        {
          "text": "数据结构",
          "link": "/structure/"
        },
        {
          "text": "算法",
          "link": "/algorithm/"
        }
      ]
    },
    {
      "text": "设计模式",
      "items": [
        {
          "text": "设计模式",
          "link": "/design/"
        }
      ]
    },
    {
      "text": "架构设计",
      "items": [
        {
          "text": "架构设计",
          "link": "/architecture/"
        }
      ]
    },
    {
      "text": "个人成长",
      "items": [
        {
          "text": "个人成长",
          "link": "/growth/"
        }
      ]
    },
    {
      "text": "面试",
      "items": [
        {
          "text": "面试",
          "link": "/interview/"
        }
      ]
    },
    {
      "text": "工具",
      "items": [
        {
          "text": "工具",
          "link": "/tools/"
        }
      ]
    },
    {
      "text": "关于",
      "items": [
        {
          "text": "关于网站",
          "link": "/about/"
        },
        {
          "text": "网站用法",
          "items": [
            {
              "text": "markdown-examples",
              "link": "/about/examples/markdown-examples"
            },
            {
              "text": "api-examples",
              "link": "/about/examples/api-examples"
            }
          ]
        }
      ]
    }
  ],
  "sidebar": {
    "/guide/": {
      "base": "/guide/",
      "items": [
        {
          "text": "导读",
          "collapsed": false,
          "items": [
            {
              "text": "不写,就无法思考",
              "link": "/不写,就无法思考"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "个人成长",
          "base": "/growth/",
          "link": "/"
        }
      ]
    },
    "/structure/": {
      "base": "/structure/",
      "items": [
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "其它链接",
          "base": "/about/",
          "link": "/"
        }
      ]
    },
    "/algorithm/": {
      "base": "/algorithm/",
      "items": [
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "其它链接",
          "base": "/about/",
          "link": "/"
        }
      ]
    },
    "/design/": {
      "base": "/design/",
      "items": [
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "其它链接",
          "base": "/about/",
          "link": "/"
        }
      ]
    },
    "/architecture/": {
      "base": "/architecture/",
      "items": [
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "其它链接",
          "base": "/about/",
          "link": "/"
        }
      ]
    },
    "/growth/": {
      "base": "/growth/",
      "items": [
        {
          "text": "精彩文章",
          "collapsed": false,
          "items": [
            {
              "text": "如何超过大多数人",
              "link": "/如何超过大多数人.md"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "其它链接",
          "base": "/about/",
          "link": "/"
        }
      ]
    },
    "/interview/": {
      "base": "/interview/",
      "items": [
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "其它链接",
          "base": "/about/",
          "link": "/"
        }
      ]
    },
    "/tools/": {
      "base": "/tools/",
      "items": [
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "其它链接",
          "base": "/about/",
          "link": "/"
        }
      ]
    },
    "/about/": {
      "base": "/about/",
      "items": [
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "待补充",
          "collapsed": false,
          "items": [
            {
              "text": "待补充",
              "link": "/"
            }
          ]
        },
        {
          "text": "其它链接",
          "base": "/about/",
          "link": "/"
        }
      ]
    },
    "/about/examples/": {
      "base": "/about/examples/",
      "items": [
        {
          "text": "示例",
          "items": [
            {
              "text": "Markdown Examples",
              "link": "/markdown-examples"
            },
            {
              "text": "Runtime API Examples",
              "link": "/api-examples"
            }
          ]
        }
      ]
    }
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/shawndanger"
    }
  ],
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2024-2024 shawndanger."
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the MIT License.