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": "/introduction"
},
{
"text": "ガイド",
"link": "/guide"
}
],
"sidebar": [
{
"text": "はじめに",
"link": "/introduction"
},
{
"text": "基本知識",
"link": "/concepts/",
"items": [
{
"text": "WebComponentsとは?",
"link": "/concepts/webcomponents-overview"
},
{
"text": "Custom Elements",
"link": "/concepts/custom-elements"
},
{
"text": "Custom Element のライフサイクル",
"link": "/concepts/custom-element-lifecycle"
},
{
"text": "Shadow DOM",
"link": "/concepts/shadow-dom"
},
{
"text": "HTML Templates",
"link": "/concepts/html-templates"
},
{
"text": "Template と Slot の連携",
"link": "/concepts/template-slot-integration"
},
{
"text": "ES Modules",
"link": "/concepts/es-modules"
},
{
"text": "Web標準としての位置づけ",
"link": "/concepts/standards-position"
},
{
"text": "TypeScriptを使う理由とメリット",
"link": "/concepts/why-typescript"
}
]
},
{
"text": "TypeScriptで Web Components の実装方法",
"link": "/typescript/",
"items": [
{
"text": "Web Component の実装フロー",
"link": "/typescript/webcomponent-implementation-flow"
},
{
"text": "Custom Elementsの実装",
"link": "/typescript/custom-element-implementation"
},
{
"text": "TypeScriptでWebComponentsライフサイクル実装",
"link": "/typescript/lifecycle-and-events"
},
{
"text": "Shadow DOM構造をTSで記述",
"link": "/typescript/shadow-dom-in-ts"
},
{
"text": "属性とプロパティのバインディング",
"link": "/typescript/attribute-property-binding"
},
{
"text": "slotsとcontentの投影",
"link": "/typescript/slots-and-projection"
}
]
},
{
"text": "CSS設計とベストプラクティス",
"link": "/css/",
"items": [
{
"text": "BEM(Block Element Modifier)設計の基本",
"link": "/css/bem-overview"
},
{
"text": "Host-based CSS と Shadow DOM",
"link": "/css/host-based-css-shadow-dom"
},
{
"text": "Scoped CSS と Shadow DOM",
"link": "/css/scoped-css-shadow-dom"
},
{
"text": "CSS Variables を用いたテーマ管理",
"link": "/css/css-variables-theming"
}
]
},
{
"text": "ユースケース別パターン集",
"link": "/patterns/",
"items": [
{
"text": "入力部品(<ts-input>)",
"link": "/patterns/ts-input"
},
{
"text": "ボタン/トグル(<ts-toggle>)",
"link": "/patterns/ts-toggle"
},
{
"text": "状態を持つ部品とステート管理",
"link": "/patterns/stateful-components"
},
{
"text": "ストリーム連携(RxJSとの統合)",
"link": "/patterns/rxjs-integration"
},
{
"text": "イベント発火とカスタムイベントの型定義",
"link": "/patterns/custom-events"
}
]
},
{
"text": "テストとデバッグ",
"link": "/testing/",
"items": [
{
"text": "Unit Test(Vitest / Web Test Runner)",
"link": "/testing/unit-testing"
},
{
"text": "Shadow DOM内の要素テスト",
"link": "/testing/shadow-dom-testing"
},
{
"text": "E2Eテスト事例(Playwrightなど)",
"link": "/testing/e2e-testing"
}
]
},
{
"text": "実践アーキテクチャ"
},
{
"text": "補足情報"
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/shuji-bonji/WebComponents-with-TypeScript"
}
],
"search": {
"provider": "local"
},
"footer": {
"message": "Released under the CC-BY-4.0 license.",
"copyright": "Copyright © 2025 shuji-bonji"
}
}Page Data
{
"title": "Runtime API Examples",
"description": "VitePress の Runtime API 使用例を紹介。useData() による site、theme、page、frontmatter データへのアクセス方法を .md および .vue ファイルで実践的に解説します。",
"frontmatter": {
"title": "Runtime API Examples",
"description": "VitePress の Runtime API 使用例を紹介。useData() による site、theme、page、frontmatter データへのアクセス方法を .md および .vue ファイルで実践的に解説します。",
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md"
}Page Frontmatter
{
"title": "Runtime API Examples",
"description": "VitePress の Runtime API 使用例を紹介。useData() による site、theme、page、frontmatter データへのアクセス方法を .md および .vue ファイルで実践的に解説します。",
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.