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

{
  "nav": [
    {
      "text": "Showcase",
      "link": "/showcase/ubuntu-desktop"
    },
    {
      "text": "Concepts",
      "link": "/concepts/gridstack-grids"
    },
    {
      "text": "Guides",
      "link": "/guides/react/simple"
    },
    {
      "text": "API",
      "link": "/api/react/gridstack-items"
    }
  ],
  "sidebar": {
    "/api/": [
      {
        "text": "API",
        "items": [
          {
            "text": "React",
            "collapsed": false,
            "items": [
              {
                "text": "Gridstack containers",
                "link": "/api/react/gridstack-containers.md"
              },
              {
                "text": "Gridstack Items",
                "link": "/api/react/gridstack-items.md"
              }
            ]
          },
          {
            "text": "Vue",
            "collapsed": true,
            "items": [
              {
                "text": "Subgrids",
                "link": "subgrids"
              }
            ]
          }
        ]
      }
    ],
    "/concepts/": [
      {
        "text": "Concepts",
        "items": [
          {
            "text": "Gridstack Grids",
            "link": "/concepts/gridstack-grids"
          },
          {
            "text": "Gridstack Items",
            "link": "/concepts/gridstack-items"
          },
          {
            "text": "Gridstack Subgrids",
            "link": "/concepts/gridstack-subgrids"
          },
          {
            "text": "Gridstack Droppables",
            "link": "/concepts/gridstack-droppables"
          },
          {
            "text": "One-way binding",
            "link": "/concepts/one-way-binding"
          },
          {
            "text": "Advantages",
            "link": "/concepts/advantages"
          },
          {
            "text": "How it works?",
            "link": "/concepts/how-it-works"
          }
        ]
      }
    ],
    "/guides/": [
      {
        "text": "Guides",
        "items": [
          {
            "text": "React",
            "collapsed": false,
            "items": [
              {
                "text": "Using CRA (Create React App)",
                "link": "/guides/react/cra"
              },
              {
                "text": "Adding items",
                "link": "/guides/react/adding-items"
              },
              {
                "text": "Removing items",
                "link": "/guides/react/removing-items"
              },
              {
                "text": "Simple",
                "link": "/guides/react/simple"
              },
              {
                "text": "Drag and drop into trash",
                "link": "/guides/react/drag-and-drop-into-trash"
              },
              {
                "text": "drag and drop",
                "link": "/guides/react/drag-and-drop"
              },
              {
                "text": "Nested",
                "link": "/guides/react/nested"
              },
              {
                "text": "Using APIs",
                "link": "/guides/react/using-apis"
              }
            ]
          },
          {
            "text": "Vue",
            "collapsed": true,
            "items": [
              {
                "text": "Nested",
                "link": "/guides/vue/nested"
              },
              {
                "text": "Using APIs",
                "link": "/guides/vue/using-apis"
              }
            ]
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/shibisuriya/declarative-gridstack"
    }
  ]
}

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.