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": "Home",
"link": "/"
},
{
"text": "指南",
"link": "/guide/basics/getting-started"
},
{
"text": "Examples",
"link": "/components/"
},
{
"text": "Test",
"link": "/components/TSelect/base"
}
],
"sidebar": {
"/guide/": [
{
"text": "指南",
"items": [
{
"text": "快速开始",
"link": "/guide/basics/getting-started"
}
]
},
{
"text": "Examples",
"items": [
{
"text": "Markdown语法示例",
"link": "/guide/basics/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/guide/basics/api-examples"
}
]
}
],
"/components/": [
{
"text": "总览",
"link": "/components/"
},
{
"text": "图片旋转",
"link": "/components/canvas/rotator"
},
{
"text": "TSelect",
"link": "/components/TSelect/base"
}
],
"/architecture/": [
{
"text": "总览",
"link": "/architecture/"
},
{
"text": "技术概览",
"link": "/architecture/overview"
},
{
"text": "模块介绍",
"link": "/architecture/modules"
}
],
"/performance/": [
{
"text": "总览",
"link": "/performance/"
},
{
"text": "渲染管线",
"link": "/performance/render-pipeline"
}
],
"/projects/": [
{
"text": "总览",
"link": "/projects/"
},
{
"text": "可视化引擎",
"link": "/projects/visual-engine"
},
{
"text": "Cesium 示例",
"link": "/projects/cesium-demo"
}
]
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/Justfine0420"
}
]
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "guide/basics/api-examples.md",
"filePath": "guide/basics/api-examples.md"
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.