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": "/home_page/logo.svg",
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/XMuli/QuickUtilitiesSuite"
},
{
"icon": "gmail",
"link": "https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1&to=xmulitech@gmail.com&su=%5BQuick%20Utilities%20Suite%5D%20Suggestions%20and%20Feedback"
}
],
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "示例",
"link": "/markdown-examples"
},
{
"text": "隐私协议",
"link": "/privacy/open-source-license"
}
],
"sidebar": [
{
"text": "示例",
"items": [
{
"text": "Markdown 示例",
"link": "/markdown-examples"
},
{
"text": "运行时 API 示例",
"link": "/api-examples"
}
]
},
{
"text": "隐私协议",
"items": [
{
"text": "开源许可协议",
"link": "/privacy/open-source-license"
},
{
"text": "软件许可协议",
"link": "/privacy/license"
},
{
"text": "隐私安全协议",
"link": "/privacy/privacy-and-data-protection"
},
{
"text": "功能介绍",
"link": "/privacy/functions"
}
]
}
]
}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.