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
{
"search": {
"provider": "local",
"options": {
"locales": {
"/": {
"placeholder": "搜索全站内容",
"translations": {
"button": {
"text": "搜索"
},
"modal": {
"noResultsText": "未找到匹配结果",
"resetButtonTitle": "清除查询",
"footer": {
"selectText": "选择",
"navigateText": "跳转",
"closeText": "关闭"
}
}
}
}
}
}
},
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "作品集",
"link": "/portfolio/"
},
{
"text": "AIGC",
"link": "/aigc/"
},
{
"text": "创作资源",
"items": [
{
"text": "3D建模",
"link": "/resources/3d-modeling"
},
{
"text": "视频剪辑",
"link": "/resources/video-editing"
},
{
"text": "平面工具",
"link": "/resources/graphic-tools"
},
{
"text": "网站搭建",
"link": "/resources/web-build"
}
]
},
{
"text": "博客",
"link": "/blog/"
},
{
"text": "随记",
"link": "/notes/"
}
],
"sidebar": [
{
"text": "快速开始",
"items": [
{
"text": "Markdown 示例",
"link": "/markdown-examples"
},
{
"text": "运行时 API 示例",
"link": "/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/han-yujie"
},
{
"icon": "youtube",
"link": "https://www.youtube.com/@yujie1992"
},
{
"icon": {
"svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"#000\"><path d=\"M19.589 6.686a4.793 4.793 0 0 1-3.77-4.245V2h-3.445v13.672a2.896 2.896 0 0 1-5.201 1.743l-.002-.001-.002-.001a2.895 2.895 0 0 1 3.183-4.51v-3.5a6.329 6.329 0 0 0-5.394 10.692 6.33 6.33 0 0 0 10.857-4.424V8.687a8.182 8.182 0 0 0 4.773 1.526V6.79a4.831 4.831 0 0 1-1.003-.104z\"/></svg>"
},
"link": "https://www.douyin.com/"
},
{
"icon": {
"svg": "<svg t=\"1767350047155\" class=\"icon\" viewBox=\"0 0 1614 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"17043\" width=\"200\" height=\"200\"><path d=\"M1077.76 271.714v97.714h-64.59v312.635h80.738c16.147 0 20.204 7.877 24.3 23.512 4.057 78.179 4.057 78.179-68.647 78.179H746.81c20.244-35.21 32.295-66.481 52.5-93.814 4.096-3.939 16.147-7.877 28.2-7.877h80.698V369.428h-64.59v-97.674h234.141zM742.754 682.22c-20.243 35.21-32.295 62.543-48.443 93.775-4.056 3.939-12.051 11.697-16.147 11.697H524.76c20.243-39.148 40.448-74.2 52.5-101.69h165.493v-3.782z m585.256-445.715c-4.096 27.293 8.152 35.21 36.352 39.148 80.66 0 121.108 42.93 125.204 121.305v66.441c64.55-3.938 104.999 23.552 125.203 74.201v175.892c-32.295 62.503-64.59 78.139-133.199 70.42-44.307-7.878-68.608-31.272-76.603-82.078h80.7c16.147 0 24.3-3.939 24.3-23.552v-78.179c0-23.512-12.052-35.21-36.352-35.21h-145.25v218.86h-105V560.956H1118.01V459.264h100.903v-86.055h-68.647v-97.753c20.244 0 44.347-3.938 68.647-3.938v-35.21h109.096v0.197z m-1009.152 0V689.94c0 66.48-44.308 97.752-104.96 89.836-40.448-7.877-64.59-35.21-64.59-82.078h68.646V236.505h100.904zM141.39 377.147c-4.096 31.271-8.153 58.565-8.153 89.836v27.333c-4.096 82.078-12.052 164.234-68.647 242.334-20.205-35.21-40.448-70.42-60.456-105.433C0 627.28 0 623.301 0 615.582 8.153 584.31 16.148 549.1 20.204 513.89c4.096-42.929 8.192-89.836 12.091-136.9h109.056v0.157z m355.249-3.741c4.057 62.503 4.057 125.046 16.148 183.768 16.108 66.481-8.192 121.305-44.347 175.892-48.443-42.93-76.643-168.172-76.643-355.722H496.64v-3.938z m266.358-136.901c-24.3 50.806-52.5 97.713-72.704 144.62 44.308-3.939 80.7-3.939 125.204-7.877-24.3 46.868-44.347 86.016-68.648 128.945-4.056 3.939-4.056 11.697-8.152 15.636-24.3 42.93-24.3 42.93 28.2 42.93h20.204c-12.052 27.332-24.3 50.884-40.448 74.2-4.057 3.938-8.153 7.916-12.052 7.916h-44.308c-20.244 0-44.347 0-64.59-3.938-28.16-3.939-36.313-23.552-24.262-46.868 12.052-31.271 28.2-58.604 40.41-89.876 4.095-11.658 8.191-19.574 16.147-35.21h-48.443c-44.308 0-56.557-19.574-40.409-58.565 24.3-54.784 56.596-113.348 88.852-171.913h105z m564.972 132.923v74.2c0 3.939 12.092 15.636 16.148 15.636 12.052 0 36.352-3.938 36.352-7.877 4.096-23.552 4.096-46.907-4.056-70.459 0-7.522-24.3-7.522-48.444-11.5z m286.602-62.504v31.272c-24.3 39.148-60.455 39.148-100.903 35.21-12.052-50.846-4.057-82.117 24.3-93.815 28.2-15.793 48.246-3.938 76.603 27.333z\" p-id=\"17044\"></path></svg>"
},
"link": "https://www.xiaohongshu.com/"
}
],
"footer": {
"message": "基于 VitePress 构建",
"copyright": "Copyright © 2026 宇杰"
}
}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.