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
{
"search": {
"provider": "local",
"options": {
"translations": {
"button": {
"buttonText": "搜索",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"noResultsText": "无法找到相关结果",
"resetButtonTitle": "清除查询",
"footer": {
"selectText": "选择",
"navigateText": "切换",
"closeText": "关闭"
}
}
}
}
},
"nav": [
{
"text": "Home",
"link": "/"
},
{
"text": "Examples",
"link": "/markdown-examples"
},
{
"text": "分类",
"link": "/categories"
},
{
"text": "标签",
"link": "/tags"
}
],
"sidebar": {
"/modern-css-with-tailwind/": [
{
"text": "Tailwind 现代 CSS 样式 (第二版)",
"items": [
{
"text": "前言",
"link": "/modern-css-with-tailwind/preface"
},
{
"text": "简介",
"link": "/modern-css-with-tailwind/introduction"
},
{
"text": "第 1 章 Tailwind 入门",
"link": "/modern-css-with-tailwind/ch01"
},
{
"text": "第 2 章 Tailwind 基础",
"link": "/modern-css-with-tailwind/ch02"
},
{
"text": "第 3 章 排版",
"link": "/modern-css-with-tailwind/ch03"
},
{
"text": "第 4 章 盒子(The Box)",
"link": "/modern-css-with-tailwind/ch04"
},
{
"text": "第 5 章 页面布局]",
"link": "/modern-css-with-tailwind/ch05"
},
{
"text": "第 6 章 动画",
"link": "/modern-css-with-tailwind/ch06"
},
{
"text": "第 7 章 响应式设计",
"link": "/modern-css-with-tailwind/ch07"
},
{
"text": "第 8 章 自定义 Tailwind",
"link": "/modern-css-with-tailwind/ch08"
}
]
}
],
"/keyword-research/": [
{
"text": "关键词研究",
"items": [
{
"text": "第一章 关键词研究概述",
"link": "/keyword-research/ch01"
},
{
"text": "第二章 关键词基础理解",
"link": "/keyword-research/ch02"
}
]
}
],
"/seo/": [
{
"text": "SEO 教程",
"items": [
{
"text": "1. 搜索引擎的工作原理",
"link": "/seo/how-do-search-engines-work"
},
{
"text": "2. SEO基础知识",
"link": "/seo/seo-basics"
},
{
"text": "3. 关键词分析",
"link": "/seo/keyword-research"
},
{
"text": "4. SEO内容",
"link": "/seo/seo-content"
},
{
"text": "5. 页面内SEO",
"link": "/seo/on-page-seo"
},
{
"text": "6. 链接建设",
"link": "/seo/link-building"
},
{
"text": "7. 技术性SEO",
"link": "/seo/technical-seo"
}
]
}
],
"/": [
{
"text": "导航",
"items": [
{
"text": "首页",
"link": "/"
},
{
"text": "分类",
"link": "/categories"
},
{
"text": "标签",
"link": "/tags"
}
]
},
{
"text": "Examples",
"items": [
{
"text": "Markdown Examples",
"link": "/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/api-examples"
}
]
}
]
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/chaosparks/learning"
}
]
}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.