This module provides a Storybook-like experience for Nuxt components, allowing you to document and test your Vue components using .stories.vue files. It automatically scans a specified directory for story files, generates dynamic routes, and creates an interactive UI for viewing and testing components.
Unlike Storybook, which can be complex and heavy, this module is lightweight and seamlessly integrates into Nuxt, making it easy to set up and use. All stories are written as standard Vue components, ensuring a smooth and intuitive development experience.
- 📦 Automatic scanning of
.stories.vuefiles and registration as pages. - ⚡ Live reloading with file-watching support.
- đź› Extracts and displays component props dynamically.
- 🏗 Nuxt DevTools Integration for quick access.
- đź“‹ Built-in component previewing with
EnhancedPreview. - 🔄 Supports dynamic prop manipulation, slot usage, and an optional props editor.
- 🚀 Flexible component embedding with event handling support.
npm install --save-dev nuxt-componentsbook-moduleor
yarn add --dev nuxt-componentsbook-moduleAdd the module to your nuxt.config.ts:
export default defineNuxtConfig({
modules: [
'nuxt-componentsbook-module',
],
componentsBook: {
// Directory where `.stories.vue` files are located:
componentsDir: 'components',
disabled: false,
cache: true,
},
})To document a component, create a .stories.vue file in your components directory:
<script setup>
import { ref } from '#imports'
import CustomInput from './MyInput.vue'
const modelValue = ref('')
const label = ref('Enter Text')
const type = ref<'text' | 'password' | 'email' | 'number'>('text')
const placeholder = ref('Type something...')
const disabled = ref(false)
const readonly = ref(false)
const helperText = ref('This is a helper text.')
const size = ref<'sm' | 'md' | 'lg'>('md')
</script>
<template>
<h1>🟢 CustomInput Component</h1>
<p>
The <code>CustomInput</code> component is a versatile input field with multiple configurations.
</p>
<h2>đź› Interactive Controls</h2>
<div class="controls">
<label>
Label:
<input v-model="label" type="text">
</label>
<label>
Type:
<select v-model="type">
<option value="text">Text</option>
<option value="password">Password</option>
<option value="email">Email</option>
<option value="number">Number</option>
</select>
</label>
</div>
<h2>🔹 Preview</h2>
<EnhancedPreview
v-model="modelValue"
:component="CustomInput"
:props="{ label, type, placeholder, disabled, readonly, 'helper-text': helperText, size }"
:emits="['click']"
@click="console.log('Clicked!')"
/>
</template>Start your Nuxt development server:
npm run devVisit /componentsbook in your browser to see the list of stories.
The EnhancedPreview component is the recommended way to embed and test your components interactively. It allows for:
- Dynamic prop manipulation (via either your own UI or the optional built-in Props Editor)
- Event handling (e.g.,
@click="...") - Slots usage (e.g.,
<template #append>or other named slots) - v-model binding
- Automatic code snippet generation for copy-paste usage examples
<EnhancedPreview
v-model="modelValue"
:component="CustomInput"
:props="{
label: 'Enter Text',
type: 'text',
placeholder: 'Type something...',
disabled: false,
readonly: false,
'helper-text': 'This is a helper text.',
size: 'md',
}"
:emits="['click']"
@click="handleClick"
>
<template #append>
test slot
</template>
</EnhancedPreview>v-modelautomatically binds the parent’smodelValueref.:propspasses other props directly to the component.:emitsdeclares which events the component might emit.- The slot
#appendis injected into<slot name="append">if your component uses it.
You can optionally provide componentPropsMeta to each <EnhancedPreview>. This activates an inline props editor (<PropsEditor>) where each prop is automatically mapped to a text field, select, checkbox, or number input.
For each prop, specify a fieldType:
text→ a simple text<input>select→ a<select>, must also provide anoptions: string[]checkbox→ a<input type="checkbox" />number→ a<input type="number" />
Example:
const componentPropsMeta = {
label: { fieldType: 'text' },
variant: {
fieldType: 'select',
options: ['primary', 'secondary', 'danger']
},
disabled: { fieldType: 'checkbox' },
size: {
fieldType: 'select',
options: ['sm', 'md', 'lg']
},
}Then pass it to <EnhancedPreview ... />:
<EnhancedPreview
:component="MyButton"
:props="{ label: 'Click Me', variant: 'primary', disabled: false, size: 'md' }"
:componentPropsMeta="componentPropsMeta"
/>The built-in Props Editor appears, letting users interactively change these props. The underlying component updates live, and the code snippet also reflects the new props.
- If you omit or pass
nullforcomponentPropsMeta, no props editor is shown. - You can combine
componentPropsMetawith your own manual controls in the.stories.vuefile. Both approaches update the same reactive data, so they stay in sync.
<script setup>
import { ref } from '#imports'
import MyButton from './MyButton.vue'
import EnhancedPreview from '~/components/EnhancedPreview.vue'
const label = ref('Click Me')
const variant = ref('primary')
const size = ref('md')
// Metadata:
const buttonPropsMeta = {
label: { fieldType: 'text' },
variant: {
fieldType: 'select',
options: ['primary', 'secondary', 'danger']
},
size: {
fieldType: 'select',
options: ['sm', 'md', 'lg']
},
}
</script>
<template>
<label>
Label
<input v-model="label" type="text" />
</label>
<label>
Variant
<select v-model="variant">
<option value="primary">Primary</option>
<option value="secondary">Secondary</option>
<option value="danger">Danger</option>
</select>
</label>
<label>
Size
<select v-model="size">
<option value="sm">Small</option>
<option value="md">Medium</option>
<option value="lg">Large</option>
</select>
</label>
<EnhancedPreview
:component="MyButton"
:props="{ label, variant, size }"
:componentPropsMeta="buttonPropsMeta"
/>
</template>Now you have two ways to set props: manually via your own inputs, or via the auto-generated editor. They both affect the same variables.
If you need other field types (like color pickers, sliders, multiple checkboxes, etc.), you can fork or extend the PropsEditor.vue to handle them. The module itself provides a basic structure, but you have full control to expand it.
For users needing complete control—like custom watchers, advanced store bindings, or specialized events—the useEnhancedPreview composable is available. It:
- Lets you dynamically attach listeners or v-model watchers.
- Returns a
renderedComponentyou can put anywhere. - Generates code snippets, can freeze/unfreeze them, etc.
Below is a short summary (for deeper details, see the Advanced Examples):
import { useEnhancedPreview } from 'nuxt-componentsbook-module'
// ...
const {
renderedComponent,
generatedCode,
isFrozen,
toggleFreeze,
copyCode
} = useEnhancedPreview(myProps, myEmit, {
fullVueFile: true,
kebabCase: true,
// ...
})Then in your template:
<component :is="renderedComponent" />
<PreviewSpoiler>
<PreviewCodeBlock :code="generatedCode" />
</PreviewSpoiler>- The module scans the specified
componentsDirfor.stories.vuefiles. - Generates dynamic Vue pages for each story and registers them with Nuxt.
- Provides a UI layout for previewing and testing components interactively.
- Supports real-time editing with automatic updates when files are modified.
- Enhances DevTools, adding a Components Book tab for quick navigation.
When using nuxt-i18n-micro, you might want to ensure that locale prefixes (like /en/) are not applied to the Components Book routes. Doing so can break the generated routes. Therefore:
- Load
nuxt-componentsbook-modulefirst - Load
nuxt-i18n-microsecond
in your nuxt.config.ts:
export default defineNuxtConfig({
modules: [
'nuxt-componentsbook-module', // order matters
'nuxt-i18n-micro',
],
})When running in development mode, a Components Book tab appears in Nuxt DevTools, providing an iframe-based UI for exploring stories. It offers a quick overview of all .stories.vue files, letting you jump directly to a desired component’s page.
- Live Demo – See the module in action.
- Usage Examples – Additional
.stories.vuefiles for more patterns and ideas.
Please feel free to submit issues and pull requests to improve this module.
Enjoy a lighter, simpler alternative to Storybook directly inside your Nuxt application!


