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
{ "outlineTitle": "页面目录", "outline": [ 2, 6 ], "nav": [ { "text": "家", "items": [ { "text": "首页", "link": "/" } ] }, { "text": "ACM", "items": [ { "text": "markdown-examples", "link": "/markdown-examples" }, { "text": "API", "link": "/api-examples" }, { "text": "rating", "link": "java/src/main/resources/ingrat" } ] }, { "text": "题解", "items": [ { "text": "题解1", "link": "/题解1" } ] }, { "text": "教程", "items": [ { "text": "vitepress搭建并部署网站", "link": "/txttt/tx1" } ] }, { "text": "资源", "items": [ { "text": "软件", "link": "/sour/viod" }, { "text": "视频", "link": "/sour/look" }, { "text": "网站", "link": "/sour/web" } ] }, { "text": "文章", "items": [ { "text": "特殊", "link": "/txttt/tx1" } ] } ], "logo": "/1720977642826.jpg", "sidebar": [ { "text": "ACM", "collapsed": false, "items": [ { "text": "Markdown 示例", "link": "/markdown-examples" }, { "text": "Runtime API 示例", "link": "/api-examples" }, { "text": "rating", "link": "java/src/main/resources/ingrat" } ] }, { "text": "题解", "collapsed": false, "items": [ { "text": "题解1", "link": "/题解1" } ] }, { "text": "教程", "collapsed": false, "items": [ { "text": "vitepress搭建并部署网站", "link": "/txttt/tx1" } ] }, { "text": "资源", "collapsed": false, "items": [ { "text": "软件", "link": "/sour/viod" }, { "text": "视频", "link": "/sour/look" }, { "text": "网站", "link": "/题解1" } ] } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/HNIST-17311-CERN/ACM-Rating.github.oi" }, { "icon": { "svg": "<svg t=\"1728565674183\" class=\"icon\" viewBox=\"0 0 1129 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2524\" width=\"200\" height=\"200\"><path d=\"M234.909 9.656a80.468 80.468 0 0 1 68.398 0 167.374 167.374 0 0 1 41.843 30.578l160.937 140.82h115.07l160.936-140.82a168.983 168.983 0 0 1 41.843-30.578A80.468 80.468 0 0 1 930.96 76.445a80.468 80.468 0 0 1-17.703 53.914 449.818 449.818 0 0 1-35.406 32.187 232.553 232.553 0 0 1-22.531 18.508h100.585a170.593 170.593 0 0 1 118.289 53.109 171.397 171.397 0 0 1 53.914 118.288v462.693a325.897 325.897 0 0 1-4.024 70.007 178.64 178.64 0 0 1-80.468 112.656 173.007 173.007 0 0 1-92.539 25.75h-738.7a341.186 341.186 0 0 1-72.421-4.024A177.835 177.835 0 0 1 28.91 939.065a172.202 172.202 0 0 1-27.36-92.539V388.662a360.498 360.498 0 0 1 0-66.789A177.03 177.03 0 0 1 162.487 178.64h105.414c-16.899-12.07-31.383-26.555-46.672-39.43a80.468 80.468 0 0 1-25.75-65.984 80.468 80.468 0 0 1 39.43-63.57M216.4 321.873a80.468 80.468 0 0 0-63.57 57.937 108.632 108.632 0 0 0 0 30.578v380.615a80.468 80.468 0 0 0 55.523 80.469 106.218 106.218 0 0 0 34.601 5.632h654.208a80.468 80.468 0 0 0 76.444-47.476 112.656 112.656 0 0 0 8.047-53.109v-354.06a135.187 135.187 0 0 0 0-38.625 80.468 80.468 0 0 0-52.304-54.719 129.554 129.554 0 0 0-49.89-7.242H254.22a268.764 268.764 0 0 0-37.82 0z m0 0\" fill=\"#20B0E3\" p-id=\"2525\"></path><path d=\"M348.369 447.404a80.468 80.468 0 0 1 55.523 18.507 80.468 80.468 0 0 1 28.164 59.547v80.468a80.468 80.468 0 0 1-16.094 51.5 80.468 80.468 0 0 1-131.968-9.656 104.609 104.609 0 0 1-10.46-54.719v-80.468a80.468 80.468 0 0 1 70.007-67.593z m416.02 0a80.468 80.468 0 0 1 86.102 75.64v80.468a94.148 94.148 0 0 1-12.07 53.11 80.468 80.468 0 0 1-132.773 0 95.757 95.757 0 0 1-12.875-57.133V519.02a80.468 80.468 0 0 1 70.007-70.812z m0 0\" fill=\"#20B0E3\" p-id=\"2526\"></path></svg>" }, "link": "https://space.bilibili.com/35804528?spm_id_from=333.1007.0.0" }, { "icon": { "svg": "<svg t=\"1729516589637\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"4869\" width=\"200\" height=\"200\"><path d=\"M512 1024C229.2224 1024 0 794.7776 0 512 0 229.2224 229.2224 0 512 0c282.7776 0 512 229.2224 512 512 0 282.7776-229.2224 512-512 512z m17.066667-413.525333c34.850133 4.352 68.778667 5.12 102.741333 2.0992 23.04-2.048 44.817067-8.362667 64.170667-21.9136 38.212267-26.794667 49.783467-85.1968 24.251733-123.050667-14.626133-21.7088-36.8128-30.344533-60.757333-35.498667-35.054933-7.543467-70.4512-5.751467-105.847467-3.413333-5.666133 0.3584-6.7584 3.072-7.236267 8.209067-3.072 32.682667-6.536533 65.314133-9.813333 97.962666-2.5088 24.814933-4.932267 49.629867-7.509333 75.605334z m53.4016-33.928534c1.962667-20.906667 3.6352-39.338667 5.4272-57.770666 1.553067-15.906133 3.413333-31.778133 4.727466-47.701334 0.3584-4.283733 1.553067-6.656 5.956267-6.382933 15.616 1.041067 31.709867 0.034133 46.728533 3.652267 36.488533 8.823467 48.725333 54.306133 23.3472 83.029333-15.8208 17.902933-36.7616 23.586133-59.255466 25.088-8.465067 0.546133-17.015467 0.085333-26.9312 0.085333zM512 434.295467c-2.184533-0.648533-3.5328-1.1776-4.932267-1.4336-37.717333-6.877867-75.690667-8.328533-113.646933-2.816-20.974933 3.037867-41.0112 9.489067-57.480533 23.330133-22.9888 19.319467-21.640533 46.848 4.4032 62.0032 13.056 7.594667 28.023467 12.509867 42.5984 17.288533 14.08 4.608 28.996267 6.826667 43.144533 11.264 12.5952 3.925333 14.011733 14.318933 3.584 22.306134-3.345067 2.56-7.441067 5.085867-11.537067 5.751466-11.195733 1.826133-22.698667 4.386133-33.826133 3.566934-24.098133-1.774933-48.042667-5.461333-72.5504-8.430934-1.365333 10.615467-2.935467 23.0912-4.5568 35.9424 4.181333 1.365333 7.68 2.730667 11.264 3.618134 33.9456 8.4992 68.386133 9.608533 102.912 5.12 20.087467-2.6112 39.4752-7.901867 56.695467-19.029334 28.603733-18.4832 36.693333-57.1904-4.676267-75.383466-14.506667-6.382933-30.190933-10.410667-45.482667-15.086934-11.4176-3.4816-23.313067-5.614933-34.525866-9.5232-9.7792-3.413333-11.144533-12.202667-3.037867-18.397866 4.6592-3.549867 10.717867-6.997333 16.384-7.3728a480.853333 480.853333 0 0 1 53.384533-0.853334c15.377067 0.699733 30.651733 3.549867 46.4896 5.5296L512 434.295467z m257.143467 2.048L750.933333 614.2976h54.152534c4.778667-45.636267 9.710933-90.7264 14.062933-135.8848 0.6144-6.365867 2.3552-8.840533 8.686933-9.0112 11.434667-0.273067 22.8864-1.979733 34.286934-1.570133 23.722667 0.853333 42.3936 9.728 38.4 43.264-2.901333 24.2688-5.597867 48.571733-8.2432 72.874666-1.092267 10.069333-1.826133 20.189867-2.730667 30.4128h55.330133c3.584-35.259733 7.9872-70.058667 10.496-104.994133 3.413333-47.4624-17.7664-73.3184-64.682666-80.213333-40.96-6.007467-81.339733-0.341333-121.5488 7.133866z m-483.498667 134.6048c-8.738133 1.297067-16.384 2.798933-24.098133 3.4816-25.6512 2.235733-51.319467 3.9424-76.305067-4.266667-13.909333-4.590933-24.6784-12.578133-29.7984-25.9584-7.901867-20.701867 0.887467-47.104 19.831467-60.3136 17.373867-12.117333 37.717333-15.9232 58.453333-15.9232 22.545067-0.017067 45.090133 2.423467 68.232533 3.84L307.2 432.298667c-15.069867-1.723733-29.4912-3.925333-43.997867-4.9152-41.0112-2.798933-80.64 2.6112-117.469866 20.462933-30.020267 14.557867-52.053333 36.010667-58.6752 68.130133-7.850667 38.144 11.537067 69.495467 51.7632 85.845334 19.1488 7.765333 39.287467 12.509867 60.0064 12.5952 24.746667 0.1024 49.493333-1.570133 74.205866-2.952534 3.106133-0.170667 8.311467-2.901333 8.669867-5.034666 1.979733-11.554133 2.730667-23.278933 3.9424-35.464534z\" fill=\"#DD1700\" p-id=\"4870\"></path></svg>" }, "link": "https://blog.csdn.net/CERN_8373558?spm=1011.2124.3001.5343" }, { "icon": { "svg": "<svg t=\"1729516936537\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"7740\" width=\"200\" height=\"200\"><path d=\"M512 10.44898C235.102041 10.44898 10.44898 235.102041 10.44898 512s224.653061 501.55102 501.55102 501.55102 501.55102-224.653061 501.55102-501.55102S788.897959 10.44898 512 10.44898z m257.044898 370.938775v16.718367c0 35.526531-5.22449 71.053061-15.673469 105.534694-10.44898 35.526531-26.122449 68.963265-47.020409 101.355102-20.897959 32.391837-47.020408 60.604082-76.277551 85.681633-29.257143 25.077551-64.783673 44.930612-105.534693 59.559184-41.795918 14.628571-85.681633 21.942857-132.702041 21.942857-74.187755 0-142.106122-19.853061-203.755102-59.559184 9.404082 1.044898 19.853061 2.089796 32.391836 2.089796 61.64898 0 117.028571-18.808163 165.093878-56.42449-29.257143-1.044898-54.334694-9.404082-77.322449-26.122449s-38.661224-38.661224-47.020408-64.783673c9.404082 1.044898 17.763265 2.089796 25.077551 2.089796 11.493878 0 22.987755-1.044898 34.481632-4.179592-30.302041-6.269388-56.42449-21.942857-76.277551-45.97551-19.853061-24.032653-30.302041-52.244898-30.30204-83.591837v-2.089796c18.808163 10.44898 38.661224 15.673469 59.559183 16.718367-17.763265-11.493878-32.391837-27.167347-42.840816-47.020408-10.44898-18.808163-15.673469-40.75102-15.673469-62.693877 0-24.032653 6.269388-45.97551 17.763265-66.87347 33.436735 40.75102 73.142857 73.142857 121.208163 97.175511 48.065306 24.032653 98.220408 37.616327 152.555102 40.75102-2.089796-10.44898-3.134694-20.897959-3.134694-30.302041 0-36.571429 12.538776-67.918367 38.661225-92.995918 26.122449-26.122449 57.469388-38.661224 94.040816-38.661225 38.661224 0 71.053061 13.583673 97.17551 41.795919 30.302041-5.22449 57.469388-16.718367 84.636735-31.346939-10.44898 31.346939-29.257143 55.379592-58.514286 73.142857 25.077551-3.134694 51.2-9.404082 76.277551-20.897959-18.808163 27.167347-40.75102 50.155102-66.873469 68.963265z\" fill=\"#27b9ff\" p-id=\"7741\"></path></svg>" }, "link": "https://x.com/fL5cBP04zXEn8rt" }, { "icon": { "svg": "<svg t=\"1729517089547\" class=\"icon\" viewBox=\"0 0 2640 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"8746\" width=\"200\" height=\"200\"><path d=\"M756.879105 341.650272c-67.873663-58.892105-162.867534-92.887448-273.293887-92.887448C195.751154 248.777452 0 469.425367 0 469.425367l55.147351 86.963131s30.543148 2.545262 14.379269-48.6818c13.955059-26.184021 41.250804-61.437367 94.58429-102.103052v579.266602c-22.995129 6.436296-53.391997 18.548234-32.678829 39.129752H289.92586c20.917961-20.771681-12.038798-33.293202-32.108338-39.129752v-136.654257s108.641744 42.362527 225.767696 42.362527c102.892962 0 196.526435-30.426125 266.170078-85.354056 69.629016-54.606117 114.536806-136.156908 114.244247-229.36617 0.204791-91.527049-39.232147-175.535334-107.135066-234.193392zM672.885448 759.497507c-48.155193 47.219005-118.193792 77.089268-198.969302 77.030756-90.137394 0.043884-165.997914-17.29023-216.098624-41.792037V360.154622c54.971815-38.807937 144.114509-62.709998 216.098624-62.563719 87.475108 0.07314 156.13868 32.912875 202.597032 82.706399 46.341328 50.115338 71.647672 116.687113 71.881719 194.068939-0.292559 75.392426-27.354256 137.502678-75.509449 185.116638z m331.322943-510.720055h-32.283873c-14.335386 0-25.949974 11.556076-25.949974 25.789067v592.402497c0 14.23299 11.59996 25.789066 25.935346 25.789066h32.269245c14.30613 0 25.935346-11.52682 25.935346-25.774438v-592.431753a25.891462 25.891462 0 0 0-25.949974-25.774439z m843.447281 0h-32.269246c-14.335386 0-25.949974 11.556076-25.949973 25.789067v592.402497c0 14.23299 11.59996 25.789066 25.949973 25.789066h32.269246c14.335386 0 25.949974-11.52682 25.949973-25.774438v-592.431753a25.891462 25.891462 0 0 0-25.949973-25.774439z m758.780738 0h-30.03117c-23.609502 0-30.133566 3.027985-40.738826 24.194621-10.590632 21.06424-244.286673 481.347142-244.286673 481.347142s-233.754553-460.282902-244.286674-481.347142c-10.649144-21.166636-17.158579-24.19462-40.753453-24.194621h-30.045798c-22.088196 0-34.024599 9.756839-21.576218 34.609717 12.492265 24.867506 300.311701 586.40504 300.311701 586.40504 7.562647 14.218362 21.400683 22.965873 36.36507 22.965873 14.920503 0 28.743911-8.747511 36.321186-22.965873 0.482722-1.023956 287.819436-561.56679 300.238561-586.40504 12.433753-24.867506 0.555862-34.609717-21.546962-34.609717zM1592.778367 871.255003c12.199706 15.417854 20.947217 21.503078 44.527463 21.503079h48.38924c30.45538 0 19.747725-13.750268 11.117238-25.013785-21.503078-28.188049-233.608274-296.215876-233.608274-296.215877s219.740983-269.519878 241.258689-297.722555c8.630487-11.263517 19.352771-25.013785-11.117238-25.013785h-48.374612c-23.594875 0-32.357013 6.070597-44.542091 21.532335-12.17045 15.403226-190.748396 233.608274-190.748397 233.608274S1230.941531 285.756896 1218.756453 270.339043c-12.185078-15.476365-20.947217-21.56159-44.527463-21.561591h-48.38924c-30.426125 0-19.747725 13.750268-11.117238 25.013786 21.503078 28.231933 241.404968 297.751811 241.404968 297.75181S1137.615245 839.570876 1116.112167 867.744297c-8.630487 11.263517-19.338143 25.013785 11.117237 25.013785h48.389241c23.594875 0 32.327757-6.085225 44.542091-21.503079 12.17045-15.461737 189.490393-232.174735 189.490393-232.174735l183.141866 232.145479zM987.971373 0.014628c-19.265003 0-35.282602 6.377784-48.125938 19.118723-12.799451 12.726312-19.221119 28.670771-19.221119 47.804123 0 19.104096 6.436296 35.048555 19.235747 47.789495 12.843335 12.726312 28.860935 19.118723 48.125938 19.118723 19.221119 0 35.253346-6.392412 48.067425-19.133351 12.828707-12.726312 19.250375-28.670771 19.250375-47.789495s-6.436296-35.063183-19.250375-47.804123C1023.224719 6.40704 1007.192492 0.014628 987.971373 0.014628z m843.44728 0c-19.221119 0-35.253346 6.377784-48.052797 19.118723-12.843335 12.726312-19.250375 28.670771-19.250375 47.804123 0 19.104096 6.392412 35.048555 19.235747 47.789495 12.814079 12.726312 28.817051 19.118723 48.067425 19.118723 19.265003 0 35.282602-6.392412 48.125938-19.133351 12.799451-12.726312 19.221119-28.670771 19.221119-47.789495s-6.436296-35.063183-19.221119-47.804123C1866.701256 6.40704 1850.683656 0.014628 1831.418653 0.014628z\" fill=\"#009CFF\" p-id=\"8747\"></path></svg>" }, "link": "https://www.pixiv.net/" } ], "footer": { "message": "Released under the MIT License.", "copyright": "Copyright © 2019-present Evan You" }, "editLink": { "pattern": "https://github.com/vuejs/vitepress/edit/main/docs/:path", "text": "Edit this page on GitHub" }, "search": { "provider": "local" }, "carbonAds": { "code": "your-carbon-code", "placement": "your-carbon-placement" } }
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.