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": "后端", "items": [ { "text": "pixiu", "link": "/note/pixiu/readme.md" }, { "text": "go", "link": "/docs/go/readme.md" }, { "text": "JAVA", "link": "/docs/java/readme.md" } ] }, { "text": "前端", "items": [ { "text": "B站", "link": "/frontend/bilibili/readme.md" }, { "text": "javascript", "link": "/frontend/javascript/readme.md" }, { "text": "scss", "link": "/frontend/scss/readme.md" }, { "text": "vue", "link": "/frontend/vue/readme.md" }, { "text": "react", "link": "/frontend/react/readme.md" }, { "text": "html", "link": "/frontend/html/readme.md" } ] }, { "text": "运维", "items": [ { "text": "jenkis", "link": "/devops/jenkins/readme.md" }, { "text": "git", "link": "/devops/git/readme.md" }, { "text": "docker", "link": "/devops/docker/readme.md" } ] }, { "text": "资料", "items": [ { "text": "工作", "link": "/note/work/readme.md" }, { "text": "技术爬爬虾", "link": "/note/papaxia/readme.md" }, { "text": "技术书籍笔记", "link": "/books/readme.md" }, { "text": "PlantUML", "link": "/note/plantuml/readme.md" } ] } ], "sidebar": [ { "text": "Examples", "items": [ { "text": "Markdown Examples", "link": "/markdown-examples" }, { "text": "Runtime API Examples", "link": "/api-examples" } ] }, { "text": "渡一", "items": [ { "text": "访问器", "link": "/duyi/vistor" }, { "text": "知识小点", "link": "note/duyi/readme.md" } ] }, { "text": "阿崔前端", "items": [ { "text": "测试", "link": "/note/cxr/readme.md" } ] }, { "text": "貔恘ui库", "items": [ { "text": "ui库", "link": "/uniapp/readme.md" }, { "text": "运营平台交付问题", "link": "/work/pixiu/readme.md" } ] }, { "text": "Go学习", "items": [ { "text": "Go基础", "link": "/docs/go/readme.md" }, { "text": "Go学习计划", "link": "/docs/go/learning-plan.md" }, { "text": "Go示例", "items": [ { "text": "基础语法", "link": "/docs/go/examples/01-basics/main.md" }, { "text": "并发编程", "link": "/docs/go/examples/02-concurrency/main.md" }, { "text": "Web开发", "link": "/docs/go/examples/03-web/main.md" }, { "text": "微服务", "link": "/docs/go/examples/04-microservice/main.md" }, { "text": "性能优化", "link": "/docs/go/examples/05-performance/main.md" }, { "text": "部署运维", "link": "/docs/go/examples/06-deployment/README.md" } ] } ] }, { "text": "书籍资料", "items": [ { "text": " javascript算法", "link": "/books/javaScript/readme.md" } ] } ], "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.