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()
</script>

## Results

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

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

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

Results

Theme Data

{
  "search": {
    "provider": "local"
  },
  "logo": "/logo.svg",
  "nav": [
    {
      "text": "Guide",
      "items": [
        {
          "text": "What is Onu UI",
          "link": "/guide/"
        },
        {
          "text": "Getting Started",
          "link": "/guide/getting-started"
        },
        {
          "text": "Built-In",
          "link": "/guide/built-in"
        },
        {
          "text": "Dynamic Theme",
          "link": "/guide/dynamic-theme"
        }
      ]
    },
    {
      "text": "Components",
      "items": [
        {
          "text": "overview",
          "link": "/components/overview"
        },
        {
          "text": "Basic",
          "collapsed": false,
          "items": [
            {
              "text": "Button",
              "link": "/components/button"
            },
            {
              "text": "Badge",
              "link": "/components/badge"
            }
          ]
        },
        {
          "text": "Form",
          "collapsed": false,
          "items": [
            {
              "text": "Input",
              "link": "/components/input"
            },
            {
              "text": "Switch",
              "link": "/components/switch"
            },
            {
              "text": "Radio",
              "link": "/components/radio"
            }
          ]
        },
        {
          "text": "Data",
          "collapsed": false,
          "items": [
            {
              "text": "Avatar",
              "link": "/components/avatar"
            }
          ]
        },
        {
          "text": "Navigation",
          "collapsed": false,
          "items": []
        },
        {
          "text": "Feedback",
          "collapsed": false,
          "items": []
        }
      ]
    },
    {
      "text": "Examples",
      "link": "/example/",
      "target": "_blank"
    },
    {
      "text": "Playground",
      "link": "https://unocss.dev/play/#html=DwEwlgbgBAZg9gOwC4FpEFcoGcwC8CmKWAxgE774JTGVL6lQDmAhgA4oAsAfAFBRTAAFgEYodAB6oO4gDZdgYKGDQJ0KGXEZx5AejC6RvfsFZcAEmAA0SgOQBbAcygAjJFVcJ1YBAGsog8hgAXgAiQSQkViwALh0dRjAkQXRnADpiODsdXABPHIgQsWZSRnwkUIB9ZxlmXxCuAGEAsCxgHWYuawbyZiQ4BjgYAWcuAHlVKABVAEk2kdS20z5h9AjEFzcjfihphGc4cWXjcGhnZhBS0IA-MUF8O0IAZgAGZ%2Bw7eoBqAE5vtpOtnNVn0EICTlBmBBesVrlBEDJvPh6kcBODSHB0AgQPgQCgYOgZHIUcYwHZGNhSMRQuFIjE4gB3RmpBJJFLpTLZPIQVKsBCMQo6LbGHQA5b-SCA7ysVZiHKsfChCRIQpSmWsGo0QRwGTY0ihVVIVJGgW8cUQXhAA&config=JYWwDg9gTgLgBAbzgEwKYDNgDtUGEJaYDmcAvnOlBCHAOQCuWEAxgM6u0BQoksicYKKlaoYAeSz0yFKjVoABAvQC09YAHpBw0V06oAHr3hp0AQ3oAbYxmx4CxABQJOcOKwAW0GM3oxWALkQXVzhmVCwYVChA2nQLA2UHAD9QiAs4YEiQVmUwiKi4ACt6VhhgdABPXPDIqABKWgAaYNJm1y0RP0CAbWD2oU6Jeic%2BkOY06BiAYgA2AAYADlQAVgB2LhCyOuCAXWbSbaA&css=PQKgBA6gTglgLgUzAYwK4Gc4HsC2YDCAyoWABYJQIA0YAhgHYAmYcUD6AZllDhWOqgAOg7nAB0YAGLcwCAB60cggDYIAXGBDAAUKDBi0mXGADe2sGC704AWgDuCGAHNScDQFYADJ4Dc5sAACtMLKAJ5gggCMLPK2ABR2pPBIcsoAlH4WAEa0yADWTlBYqEw2yFjK3Bpw5LxxAOTllVDoYpSMYgAs3vUZ2gC%2BmsBAA&options=N4IgLgTghgdgzgMwPYQLYgFwKgGzgUwBpxp5k0BhAVzjCVQoGVHNs8iTZEVUAJMVDla4CAXyA",
      "target": "_blank"
    },
    {
      "text": "v1.1.5",
      "items": [
        {
          "text": "Release Notes",
          "link": "https://github.com/onu-ui/onu-ui/releases"
        },
        {
          "text": "Contributing",
          "link": "https://github.com/onu-ui/onu-ui/blob/main/CONTRIBUTING.md"
        }
      ]
    },
    {
      "component": "ThemePalette"
    }
  ],
  "sidebar": [
    {
      "text": "Guide",
      "items": [
        {
          "text": "What is Onu UI",
          "link": "/guide/"
        },
        {
          "text": "Getting Started",
          "link": "/guide/getting-started"
        },
        {
          "text": "Built-In",
          "link": "/guide/built-in"
        },
        {
          "text": "Dynamic Theme",
          "link": "/guide/dynamic-theme"
        }
      ]
    },
    {
      "text": "Components",
      "items": [
        {
          "text": "Basic",
          "collapsed": false,
          "items": [
            {
              "text": "Button",
              "link": "/components/button"
            },
            {
              "text": "Badge",
              "link": "/components/badge"
            }
          ]
        },
        {
          "text": "Form",
          "collapsed": false,
          "items": [
            {
              "text": "Input",
              "link": "/components/input"
            },
            {
              "text": "Switch",
              "link": "/components/switch"
            },
            {
              "text": "Radio",
              "link": "/components/radio"
            }
          ]
        },
        {
          "text": "Data",
          "collapsed": false,
          "items": [
            {
              "text": "Avatar",
              "link": "/components/avatar"
            }
          ]
        },
        {
          "text": "Navigation",
          "collapsed": false,
          "items": []
        },
        {
          "text": "Feedback",
          "collapsed": false,
          "items": []
        }
      ]
    },
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "editLink": {
    "pattern": "https://github.com/onu-ui/onu-ui/edit/main/docs/:path",
    "text": "Suggest changes to this page"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/onu-ui/onu-ui"
    },
    {
      "icon": "bluesky",
      "link": "https://bsky.app/profile/zyyv.bsky.social"
    }
  ],
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2022-present Chris"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the MIT License.