useFetchComponentMeta

Read the component metadata generated by nuxt-component-meta, including the types and descriptions of props, slots and events. ComponentProps and the other component docs components are built on it; call it directly to render your own API tables. Available only with component docs enabled.

useFetchComponentMeta() requests /api/component-meta/{name}.json and returns the result of useAsyncData. During server rendering the endpoint is added to the prerender list, and client navigation reuses the payload instead of requesting again.

Set movkNuxtDocs.componentDocs: true in nuxt.config and install nuxt-component-meta, vue-component-meta and prettier, see Feature Flags. When disabled, the function is not auto-imported.

Usage

<script setup lang="ts">
const { data } = await useFetchComponentMeta('MyButton')
</script>

<template>
  <ul>
    <li v-for="prop in data?.meta?.props" :key="prop.name">
      <code>{{ prop.name }}</code>: {{ prop.type }}
    </li>
  </ul>
</template>

Signature

function useFetchComponentMeta(name: string): AsyncData<Partial<ComponentMetaData> | undefined, NuxtError | undefined>

interface ComponentMetaData {
  meta: ComponentMeta // from vue-component-meta
}

Parameters

NameTypeDescription
namestringPascalCase component name, as registered by nuxt-component-meta

Return Value

The result of useAsyncData; the commonly used fields are:

NameTypeDescription
dataRef<Partial<ComponentMetaData> | undefined>data.meta holds props, slots, events, exposed and more; an empty object when the component is missing or the request fails
statusRef<AsyncDataRequestStatus>Request status
refresh() => Promise<void>Request again

Notes

  • On the client the call is lazy, so data can be empty on first render; guard against it in templates.
  • Only the layer's own docs components are scanned by default; add your components to componentMeta.include, see ComponentProps.

Changelog

No recent changes
Copyright © 2024 - 2026