Skip to content

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();

var fruits = ['apple', 'banana', 'orange'];

</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Theme Data - Loop: v-for JSON array 
<ul>
  <li v-for="item in theme.nav">
      {{ item.text }}
  </li>
</ul>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter - Single Item
<pre>{{ frontmatter.name }}</pre>

### Page Frontmatter - Loop: v-for
<ul>
    <li v-for="(value, key) in frontmatter">
      {{ key }}: {{ value }}
    </li>
</ul>

### Simple JS Array - Loop: v-for w index
<div>
    <p v-for="(x, index) in fruits">
      {{ index }}:  {{ x }} <br>
    </p>
</div>

Results

Theme Data

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Examples",
      "link": "/markdown-examples"
    }
  ],
  "sidebar": [
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "More MD Examples",
          "link": "/markdown"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        },
        {
          "text": "Pinboard Topics",
          "link": "/pinboard"
        },
        {
          "text": "Javascript Links",
          "link": "/javascript"
        },
        {
          "text": "Node Links",
          "link": "/node"
        },
        {
          "text": "CSS/HTML Links",
          "link": "/csshtml"
        },
        {
          "text": "Reports List",
          "link": "/reports_index.md"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ],
  "footer": {
    "message": "Vitepress Powered Site",
    "copyright": "Copyright © 2025"
  }
}

Theme Data - Loop: v-for JSON array

  • Home
  • Examples

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep",
    "name": "rick",
    "date": "06/01/25"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md"
}

Page Frontmatter - Single Item

rick

Page Frontmatter - Loop: v-for

  • outline: deep
  • name: rick
  • date: 06/01/25

Simple JS Array - Loop: v-for w index

0: apple

1: banana

2: orange

More

Check out the documentation for the full list of runtime APIs.

Table - Included MD File

FlagDateDescriptionLink
02/20/25javascript google get tomorrow's date????
02/20/25websocket vs socket.o guide web server javascript pythonjsdev.space
02/19/25node.js streams javascriptmedium.com
02/19/25http polling vs websockets vs sse servers javascriptjavascript.plainenglish.io
02/19/25una ui components for vue html javascriptunaui.com
02/18/25replicad javascript 3d cad libraryreplicad.xyz
02/18/25fixi small version of htmx javascriptgithub.com
02/18/25vue is easy vue.js good detailed overview javascriptfadamakis.com
02/17/25ways to abort javascript executionwww.geeksforgeeks.org
02/17/25javascript generators guide to yield and iteratorsjsdev.space
02/16/25comprehensive list of 500 javascript project ideas for developersgithub.com
02/16/25simple web components demo of javascript html componentsgithub.com
02/10/25flatpickr lightweight javascript datetimepicker htmlgithub.com
02/10/25var let and const review javascriptwww.freecodecamp.org
02/04/25html javascript get the filename and extension from input type filestackoverflow.com
02/04/25arrow functions in javascriptui.dev
02/04/25qr code html web component javascriptscottjehl.com
02/04/25jscanify javascript mobile document scannercolonelparrot.github.io
02/04/25typescript cheatsheet javascriptdevhints.io
02/04/25javascript arrow functions cheatsheetdev.to

Vitepress Powered Site