ComponentCode
::component-code. Readers switch prop values above the live preview and the Vue snippet below updates in sync, ready to copy.ComponentCode needs no separate example file: give the component name and initial props in the frontmatter and you get an interactive preview with the matching Vue code.
Usage
name is the PascalCase component name, either a Nuxt UI component or an auto-imported component from your project. Every key in props gets a control, and items provides the choices for a key:
<template>
<UBadge label="New" color="primary" variant="solid" />
</template>
::component-code
---
name: UBadge
props:
label: New
color: primary
variant: solid
items:
color: [primary, secondary, success, warning, error, neutral]
variant: [solid, outline, soft, subtle]
---
::
Boolean props get true / false choices automatically, number props get a number input and everything else a text input. Boolean and string props equal to the component's default are left out of the snippet.
Controlling the generated code
| Field | Effect |
|---|---|
ignore | No control, but still written to the code; for fixed props |
hide | Neither a control nor written to the code; for props that only affect the preview |
external | Declared as a ref in <script setup> and bound by variable in the template |
model | Bound with v-model:{key}; modelValue is always bound with v-model |
slots | Slot content, keyed by slot name with template strings as values |
::component-code
---
name: UInput
props:
modelValue: ''
placeholder: Search docs
class: w-64
external: [modelValue]
hide: [class]
slots:
trailing: <UKbd value="/" />
---
::
In the generated code above, modelValue becomes const value = ref("") bound with v-model="value", while class only applies to the preview.
API
Props
| Prop | Default | Type |
|---|---|---|
name | string | |
props | Record<string, any> | |
items | Record<string, any[]> | |
model | string[] | |
hide | string[] | |
ignore | string[] | |
slots | Record<string, any> | |
prettier | false | boolean 是否使用 Prettier 格式化代码 |
collapse | false | boolean | { icon?: string ; name?: string | undefined; openText?: string | undefined; closeText?: string | undefined; open?: boolean | undefined; } | undefined是否折叠代码块 |
highlights | number[] | |
overflowHidden | boolean | |
elevated | boolean |
Changelog
ComponentExample
Render a Vue file from the examples directory as a live preview with its highlighted source below. Supports line highlights, collapsing, adjustable options and client-only rendering for showing components in realistic compositions.
CommitChangelog
Fetch the GitHub commit history of a component or source file with `:commit-changelog` and show it as a timeline grouped by release. The file path is inferred from the name and can be tuned by directory, extension, casing and author, or cover several files.