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

{
  "logo": {
    "light": "/logo.png",
    "dark": "/logo.png"
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "外卖餐饮券",
      "items": [
        {
          "text": "美团外卖红包",
          "link": "/life/meituan/mt01"
        },
        {
          "text": "饿了么外卖红包",
          "link": "/life/eleme/el01"
        },
        {
          "text": "大牌餐饮券",
          "link": "/life/brand/dp01"
        }
      ]
    },
    {
      "text": "特惠电影票",
      "link": "/film/index"
    },
    {
      "text": "出行优惠券",
      "items": [
        {
          "text": "打车",
          "link": "/trip/taxi"
        },
        {
          "text": "快递",
          "link": "/trip/express"
        },
        {
          "text": "酒店",
          "link": "/trip/hotel"
        },
        {
          "text": "景点",
          "link": "/trip/scenic"
        }
      ]
    },
    {
      "text": "电商优惠券",
      "link": "/mall/index"
    },
    {
      "text": "特价会员",
      "link": "/vip/index"
    },
    {
      "text": "关于我们",
      "items": [
        {
          "text": "平台介绍",
          "link": "/about/profile"
        },
        {
          "text": "联系方式",
          "link": "/about/contact"
        },
        {
          "text": "合作共赢",
          "link": "/about/partner"
        }
      ]
    }
  ],
  "sidebar": {
    "/life/": [
      {
        "text": "美团",
        "items": [
          {
            "text": "美团外卖红包天天领",
            "link": "/life/meituan/mt01"
          },
          {
            "text": "美团赚超值券包全品类",
            "link": "/life/meituan/mt02"
          },
          {
            "text": "美团赏金红包&霸王餐",
            "link": "/life/meituan/mt03"
          },
          {
            "text": "美团外卖惊喜红包",
            "link": "/life/meituan/mt04"
          },
          {
            "text": "零售商家福利活动",
            "link": "/life/meituan/mt05"
          },
          {
            "text": "超值券包&外卖&酒店聚合页",
            "link": "/life/meituan/mt06"
          },
          {
            "text": "美团美食团购 18元神券到店吃",
            "link": "/life/meituan/mt07"
          }
        ]
      },
      {
        "text": "饿了么",
        "items": [
          {
            "text": "饿了么红包节天天领红包活动",
            "link": "/life/eleme/el01"
          },
          {
            "text": "饿了么21城消费日活动",
            "link": "/life/eleme/el02"
          },
          {
            "text": "饿了么红包天天领不停",
            "link": "/life/eleme/el03"
          },
          {
            "text": "饿了么零售会场265元神券包",
            "link": "/life/eleme/el04"
          },
          {
            "text": "饿了么红包节-水果买菜5折红包",
            "link": "/life/eleme/el05"
          }
        ]
      },
      {
        "text": "大牌餐饮",
        "items": [
          {
            "text": "大牌点餐",
            "link": "/life/brand/dp01"
          },
          {
            "text": "星巴克优惠点餐低至8折起",
            "link": "/life/brand/dp02"
          },
          {
            "text": "KFC最低5折",
            "link": "/life/brand/dp03"
          },
          {
            "text": "麦当劳点餐最低5折",
            "link": "/life/brand/dp04"
          },
          {
            "text": "必胜客全场7折起",
            "link": "/life/brand/dp05"
          },
          {
            "text": "库迪咖啡点餐6折起",
            "link": "/life/brand/dp06"
          },
          {
            "text": "百果园水果9折起",
            "link": "/life/brand/dp07"
          },
          {
            "text": "华莱士",
            "link": "/life/brand/dp08"
          },
          {
            "text": "汉堡王",
            "link": "/life/brand/dp09"
          },
          {
            "text": "奈雪茶",
            "link": "/life/brand/dp10"
          },
          {
            "text": "喜茶",
            "link": "/life/brand/dp11"
          },
          {
            "text": "蜜雪冰城",
            "link": "/life/brand/dp12"
          },
          {
            "text": "古茗5折起",
            "link": "/life/brand/dp13"
          }
        ]
      }
    ],
    "/film/": [
      {
        "text": "特惠电影票",
        "items": [
          {
            "text": "电影票在线预定",
            "link": "/film/index"
          }
        ]
      }
    ],
    "/trip/": [
      {
        "text": "打车/代驾",
        "items": [
          {
            "text": "滴滴打车 天天5折起",
            "link": "/trip/taxi/didi"
          },
          {
            "text": "花小猪打车 首单立减",
            "link": "/trip/taxi/huaxiaozhu"
          },
          {
            "text": "T3出行 超值礼包",
            "link": "/trip/taxi/t3"
          },
          {
            "text": "同程大厂 领券打车更优惠",
            "link": "/trip/taxi/tongcheng"
          },
          {
            "text": "滴滴学生特惠",
            "link": "/trip/taxi/huaxiaozhu"
          },
          {
            "text": "滴滴代驾 最高立减20",
            "link": "/trip/taxi/huaxiaozhu"
          }
        ]
      },
      {
        "text": "快递/搬家",
        "items": [
          {
            "text": "特价寄快递",
            "link": "/trip/"
          },
          {
            "text": "滴滴货运",
            "link": "/trip/"
          },
          {
            "text": "滴滴送货新客",
            "link": "/trip/"
          }
        ]
      },
      {
        "text": "飞机/火车",
        "items": [
          {
            "text": "飞猪机票",
            "link": "/trip/"
          },
          {
            "text": "同程飞机票",
            "link": ""
          },
          {
            "text": "飞猪火车票",
            "link": "/trip/"
          }
        ]
      },
      {
        "text": "酒店/景点",
        "items": [
          {
            "text": "飞猪酒店",
            "link": "/trip/"
          }
        ]
      }
    ],
    "/mall/": [
      {
        "text": "电商优惠券",
        "items": [
          {
            "text": "电商优惠券查询",
            "link": "/mall/index"
          },
          {
            "text": "淘宝",
            "link": "/mall/taobao"
          },
          {
            "text": "天猫",
            "link": "/mall/tmall"
          },
          {
            "text": "京东",
            "link": "/mall/jd"
          },
          {
            "text": "拼多多",
            "link": "/mall/pdd"
          },
          {
            "text": "唯品会",
            "link": "/mall/wph"
          },
          {
            "text": "抖音",
            "link": "/mall/dy"
          }
        ]
      }
    ]
  },
  "footer": {
    "copyright": "\nCopyright&nbsp;©&nbsp;2023-2024&nbsp;上海墨松信息科技有限公司&nbsp;&nbsp;<a href=\"https://mosong.cc\">mosong.cc</a>&nbsp;&nbsp;\n<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">沪ICP备19002970号-4</a> &nbsp;&nbsp;\n<a href=\"https://beian.mps.gov.cn/#/query/webSearch?code=31010702007768\" target=\"_blank\">沪公网安备 31010702007768号</a>\n",
    "message": "\n<div class=\"ms-footer-message\">\n</div>\n"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://work.weixin.qq.com/kfid/kfca8869ef04dbf1f2a"
    }
  ],
  "outline": {
    "level": "deep",
    "label": "大纲导航"
  },
  "search": {
    "provider": "local"
  }
}

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.