Runtime API Examples
阅读时间:
1
分钟 文章字数:
118
字 发布日期:
2024-11-12
最近更新:
2024-11-19
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": "/pages/comment" }, { "text": "关于", "link": "/pages/about" }, { "text": "推荐", "items": [ { "items": [ { "text": "实用网页", "link": "/pages/webPage" }, { "text": "工具插件", "link": "/pages/tools" } ] } ] } ], "sidebar": [ { "text": "pages", "items": [ { "text": "实用网页", "link": "/pages/webPage" }, { "text": "工具插件", "link": "/pages/tools" }, { "text": "闲聊", "link": "/pages/comment" }, { "text": "关于我", "link": "/pages/about" } ], "collapsed": false }, { "text": "2024", "items": [ { "text": "api examples", "link": "/2024/api-examples" } ], "collapsed": false }, { "text": "2023", "items": [ { "text": "markdown examples", "link": "/2023/markdown-examples" } ], "collapsed": false } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/lee-holden/vitepress-blog-template" } ] }
Page Data
{ "title": "api examples", "description": "", "frontmatter": { "outline": "deep", "title": "api examples", "date": "2024-11-12T00:00:00.000Z", "info": "api测试", "tags": [ "api" ] }, "headers": [], "relativePath": "2024/api-examples.md", "filePath": "2024/api-examples.md" }
Page Frontmatter
{ "outline": "deep", "title": "api examples", "date": "2024-11-12T00:00:00.000Z", "info": "api测试", "tags": [ "api" ] }
More
Check out the documentation for the full list of runtime APIs.
1
123
2
123
3
123