useFetchComponentMeta
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.
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
| Name | Type | Description |
|---|---|---|
name | string | PascalCase component name, as registered by nuxt-component-meta |
Return Value
The result of useAsyncData; the commonly used fields are:
| Name | Type | Description |
|---|---|---|
data | Ref<Partial<ComponentMetaData> | undefined> | data.meta holds props, slots, events, exposed and more; an empty object when the component is missing or the request fails |
status | Ref<AsyncDataRequestStatus> | Request status |
refresh | () => Promise<void> | Request again |
Notes
- On the client the call is lazy, so
datacan 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.
Related
Changelog
useLocaleSeo
Inject hreflang alternate links, x-default and og:locale on multilingual sites so search engines can tell the language versions apart. The layer's app.vue already calls it globally; call it yourself only when you rewrite app.vue.
useFetchComponentExample
Read the source code, file path and name of example components under components/content/examples. ComponentExample uses it to show example code; call it directly to display example source in your own components. Available only with component docs enabled.