ComponentCode

Drive any registered Vue component from a props matrix with ::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.

Requires movkNuxtDocs.componentDocs, with the same prerequisites as ComponentProps.

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:

New
<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

FieldEffect
ignoreNo control, but still written to the code; for fixed props
hideNeither a control nor written to the code; for props that only affect the preview
externalDeclared as a ref in <script setup> and bound by variable in the template
modelBound with v-model:{key}; modelValue is always bound with v-model
slotsSlot 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.

ComponentCode and ComponentExample share the ComponentExampleExtras extension component.

API

Props

Prop Default Type
namestring
props Record<string, any>
items Record<string, any[]>
model string[]
hide string[]
ignore string[]
slots Record<string, any>
prettierfalseboolean

是否使用 Prettier 格式化代码

collapsefalseboolean | { icon?: string ; name?: string | undefined; openText?: string | undefined; closeText?: string | undefined; open?: boolean | undefined; } | undefined

是否折叠代码块

highlights number[]
overflowHiddenboolean
elevatedboolean

Changelog

No recent changes
Copyright © 2024 - 2026