Writing stories
Stories are written like in any Storybook project. The framework renders each of them in its own Nuxt app, so your components can use auto-imports, plugins, composables such as useRoute() or useRuntimeConfig(), and Nuxt components such as <NuxtLink>.
import preview from '../.storybook/preview'
import MyGreeting from './MyGreeting.vue'
const meta = preview.meta({ component: MyGreeting })
export const Default = meta.story({
args: { name: 'Nuxt' },
})
Disabling a plugin
Plugins in your app run in the Nuxt app of every story. To disable a plugin in Storybook, such as one loading analytics or a third-party SDK, set env.storybook to false:
export default defineNuxtPlugin({
env: { storybook: false },
setup() {
// Not run in stories
},
})
- type:
boolean - default:
true
env.storybook comes with @nuxtjs/storybook. Without the module, add the framework types to your app in nuxt.config.ts:export default defineNuxtConfig({
typescript: {
tsConfig: { compilerOptions: { types: ['@storybook-vue/nuxt'] } },
},
})
parameters.nuxt
Configure the Nuxt app of a story, a story file or every story (in .storybook/preview.ts) with parameters.nuxt. It is typed with CSF Factories.
route
The route the app starts on.
- type:
string - default:
'/'
export const Settings = meta.story({
parameters: {
nuxt: { route: '/settings?tab=profile' },
},
})
navigation
Lets the story navigate away from its route, in the router or to another site. When false, the story stays where it is, and each attempt is reported to the navigation spy: see Navigation.
- type:
boolean - default:
false
runtimeConfig
Values deep-merged into the runtime config of your Nuxt app for a specific story.
- type: a partial runtime config
export const Staging = meta.story({
parameters: {
nuxt: {
runtimeConfig: { public: { apiBase: 'https://staging.example.com' } },
},
},
})
endpoints
Endpoints answered from inside the preview for this story, keyed by URL. See registerEndpoint.
- type:
Record<string, Endpoint>