Skip to content
On this page

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

{
  "editLink": {
    "pattern": "https://github.com/codeforwings/vite-press-docs/edit/main/docs/src/:path"
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Examples",
      "link": "/vitePress/markdown-examples"
    },
    {
      "text": "Toc",
      "link": "/toc"
    },
    {
      "text": "SSH",
      "link": "/ssh"
    }
  ],
  "sidebar": [
    {
      "text": "code-editors",
      "items": [
        {
          "text": "docs_readme_vscode",
          "link": "/code-editors/docs_readme_vscode"
        },
        {
          "text": "docs_readme_webstorm",
          "link": "/code-editors/docs_readme_webstorm"
        }
      ],
      "collapsed": true
    },
    {
      "text": "components",
      "items": [
        {
          "text": "hello-world.vue",
          "link": "/components/hello-world.vue"
        }
      ],
      "collapsed": true
    },
    {
      "text": "docs_readme_codeforwings",
      "link": "/docs_readme_codeforwings"
    },
    {
      "text": "docs_readme_jc_dump_2023",
      "link": "/docs_readme_jc_dump_2023"
    },
    {
      "text": "index",
      "link": "/index"
    },
    {
      "text": "nodejs",
      "items": [
        {
          "text": "docs_readme_nodejs",
          "link": "/nodejs/docs_readme_nodejs"
        },
        {
          "text": "docs_readme_vuetify",
          "link": "/nodejs/docs_readme_vuetify"
        }
      ],
      "collapsed": true
    },
    {
      "text": "posix",
      "items": [
        {
          "text": "docs_bash",
          "link": "/posix/docs_bash"
        },
        {
          "text": "docs_readme_file-folder-glob-utils",
          "link": "/posix/docs_readme_file-folder-glob-utils"
        },
        {
          "text": "posix/wsl",
          "items": [],
          "collapsed": true
        }
      ],
      "collapsed": true
    },
    {
      "text": "ssh",
      "items": [
        {
          "text": "index",
          "link": "/ssh/index"
        }
      ],
      "collapsed": true
    },
    {
      "text": "toc",
      "link": "/toc"
    },
    {
      "text": "vitePress",
      "items": [
        {
          "text": "api-examples",
          "link": "/vitePress/api-examples"
        },
        {
          "text": "docs_readme_vitePress.dev",
          "link": "/vitePress/docs_readme_vitePress.dev"
        },
        {
          "text": "index.dev",
          "link": "/vitePress/index.dev"
        },
        {
          "text": "index",
          "link": "/vitePress/index"
        },
        {
          "text": "markdown-examples",
          "link": "/vitePress/markdown-examples"
        }
      ],
      "collapsed": true
    },
    {
      "text": "win32",
      "items": [
        {
          "text": "docs_readme_cygwin",
          "link": "/win32/docs_readme_cygwin"
        },
        {
          "text": "docs_readme_everything_index_query",
          "link": "/win32/docs_readme_everything_index_query"
        },
        {
          "text": "docs_readme_win32",
          "link": "/win32/docs_readme_win32"
        }
      ],
      "collapsed": true
    },
    {
      "text": "AWS",
      "link": "/posix/amazon-linux-2023/docs_readme_amazon-linux-2023"
    },
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/vitePress/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/vitePress/api-examples"
        }
      ]
    }
  ],
  "search": {
    "provider": "local",
    "options": {}
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/codeforwings/vite-press-docs"
    }
  ],
  "markdown": {
    "lineNumbers": true,
    "space_size": 2
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "vitePress/api-examples.md",
  "filePath": "vitePress/api-examples.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

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