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": "/components/index"
},
{
"text": "Canvas 介绍",
"link": "/canvas/index"
}
],
"sidebar": [
{
"text": "组件",
"base": "/components/",
"items": [
{
"text": "开发指南",
"items": [
{
"text": "技巧",
"link": "performanceTips"
},
{
"text": "组件用法",
"link": "usage"
},
{
"text": "DevTool",
"link": "devTool"
},
{
"text": "常见问题",
"link": "faq"
},
{
"text": "更新日志",
"link": "changelog"
}
]
},
{
"text": "组件列表",
"items": [
{
"text": "基础组件",
"items": [
{
"text": "见Konva官网",
"link": "konva"
}
]
},
{
"text": "反馈组件",
"items": [
{
"text": "Loading 加载",
"link": "loading"
},
{
"text": "Dialog 弹出框",
"link": "dialog"
},
{
"text": "Toast 轻提示",
"link": "toast"
}
]
},
{
"text": "展示组件",
"items": [
{
"text": "textMarquee 文本跑马灯",
"link": "textMarquee"
},
{
"text": "Listview列表",
"link": "list"
},
{
"text": "seriesRadar(雷达图)",
"link": "seriesRadar"
},
{
"text": "svg",
"link": "svg"
}
]
},
{
"text": "导航组件",
"items": [
{
"text": "Sidebar 侧边导航",
"link": "sidebar"
},
{
"text": "Tab 标签页",
"link": "tab"
},
{
"text": "Grid 宫格",
"link": "grid"
}
]
},
{
"text": "业务组件",
"items": [
{
"text": "Card",
"link": "card"
}
]
}
]
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
}
]
}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.