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": "Home",
"link": "/"
},
{
"text": "Python",
"link": "/python/"
},
{
"text": "Django",
"link": "/django/"
}
],
"sidebar": {
"/start/": {
"items": [
{
"text": "Start",
"items": [
{
"text": "Introduction",
"link": "/start/"
},
{
"text": "Install Python",
"link": "/start/installation"
},
{
"text": "IDE and Editors",
"link": "/start/ide"
}
]
}
]
},
"/python/": {
"items": [
{
"text": "Python Basic",
"collapsed": false,
"items": [
{
"text": "Introduction",
"link": "/python/"
},
{
"text": "Expression vs Statement",
"link": "/python/01_expression_statement"
},
{
"text": "Variables",
"link": "/python/02_variables"
},
{
"text": "Types & Data Structure",
"link": "/python/03_types_data_structure"
},
{
"text": "Strings",
"link": "/python/04_string"
},
{
"text": "Numerics",
"link": "/python/05_numeric"
},
{
"text": "Boolean",
"link": "/python/06_boolean"
},
{
"text": "Magic Methods",
"link": "/python/07_magic_methods"
},
{
"text": "List",
"link": "/python/08_list"
},
{
"text": "Dictionary",
"link": "/python/09_dict"
},
{
"text": "Tuples",
"link": "/python/10_tuples"
},
{
"text": "Set",
"link": "/python/11_set"
},
{
"text": "Operators",
"link": "/python/29_operators"
},
{
"text": "Lambda Function",
"link": "/python/30_lambda_function"
},
{
"text": "Error Handling",
"link": "/python/31_error_handling"
},
{
"text": "Sequence unpacking",
"link": "/python/32_sequence_unpacking"
},
{
"text": "Conditional Statement",
"link": "/python/33_conditional_statement"
},
{
"text": "Conditional Expression",
"link": "/python/34_conditional_expression"
},
{
"text": "Loops",
"link": "/python/35_loops"
},
{
"text": "For In expression",
"link": "/python/36_for_in_expression"
}
]
},
{
"text": "Python Advanced",
"collapsed": true,
"items": []
},
{
"text": "Python How To",
"collapsed": true,
"items": []
}
]
}
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
}
],
"outline": [
2,
3
],
"footer": {
"message": "Made with ❤️ by Vitepress",
"copyright": "© 2024, Dr. Kibria"
},
"externalLinkIcon": true,
"lastUpdated": {
"text": "Last Updated",
"formatOptions": {
"dateStyle": "medium",
"timeStyle": "short"
}
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "start/api-examples.md",
"filePath": "start/api-examples.md",
"lastUpdated": 1707251453000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.