Vue 3 Carousel Nuxt Module
vue3-carousel-nuxt is a Nuxt 3 module designed to seamlessly integrate the popular vue3-carousel component library into Nuxt 3 applications. It automates the setup process, registering the Carousel, Slide, Pagination, and Navigation components globally or with a user-defined prefix, and automatically includes the default carousel CSS styles, preventing duplicate imports. The current stable version is 1.1.6, with a recent history of active patch releases indicating ongoing maintenance and responsiveness to bug fixes since its initial release as v1.1.0. This module significantly simplifies the developer experience by abstracting away manual component registration and style management, allowing developers to focus directly on building interactive carousels within their Nuxt projects. Its primary differentiator is the deep integration with Nuxt's module system, providing a plug-and-play experience compared to manually adding and configuring the base vue3-carousel library.
Common errors
-
Error: Nuxt module "vue3-carousel-nuxt" not found. Did you forget to add it to your `nuxt.config.ts`'s `modules` array?
cause The `vue3-carousel-nuxt` module has not been added to the `modules` array in your `nuxt.config.ts` file, preventing Nuxt from discovering and loading it.fixAdd `'vue3-carousel-nuxt'` to the `modules` array in your `nuxt.config.ts` file, for example: `export default defineNuxtConfig({ modules: ['vue3-carousel-nuxt'] })`. -
[Vue warn]: Failed to resolve component: <Carousel>
cause The `Carousel` component (or any other `vue3-carousel` component) is not recognized by Vue. This typically happens if the `vue3-carousel-nuxt` module is not correctly configured or loaded, or if a prefix is used but not applied to the component name.fixVerify that `vue3-carousel-nuxt` is listed in your `nuxt.config.ts` `modules` array. If you have a `carousel.prefix` configured, ensure you are using the prefixed component name (e.g., `<MyCustomCarousel />`). Clear your Nuxt build cache (`.nuxt` and `node_modules/.cache`) and restart the development server.
Warnings
- gotcha Do not manually import `vue3-carousel/dist/carousel.css` in your project. The module automatically handles the import of the default styles. Explicitly importing it again can lead to duplicated styles or unexpected CSS cascade issues.
- gotcha When using the `carousel.prefix` option in `nuxt.config.ts`, all `vue3-carousel` components (e.g., `Carousel`, `Slide`, `Pagination`, `Navigation`) will have this prefix applied. Forgetting the prefix in your templates will result in 'Failed to resolve component' errors.
- gotcha The module automatically registers the `vue3-carousel` components. Avoid manually importing `Carousel`, `Slide`, etc., from `vue3-carousel` directly in your SFCs after configuring this Nuxt module, as it can lead to redundant component registrations or conflicts.
Install
-
npm install vue3-carousel-nuxt -
yarn add vue3-carousel-nuxt -
pnpm add vue3-carousel-nuxt
Imports
- Vue3 Carousel Nuxt Module Configuration
const vue3CarouselNuxt = require('vue3-carousel-nuxt');export default defineNuxtConfig({ modules: [ 'vue3-carousel-nuxt' ], carousel: { prefix: 'MyCustom' // Optional: configure component prefix } }) - Carousel Component Usage (Template)
import { Carousel } from 'vue3-carousel'; // Not needed, components are auto-imported by the module.<Carousel /> <Slide /> <Pagination /> <Navigation />
- Styling Carousel
import 'vue3-carousel/dist/carousel.css'; // The module already imports this for you.
/* In your CSS/SCSS file */ .carousel__slide { padding: 10px; }
Quickstart
import { defineNuxtConfig } from 'nuxt';
// nuxt.config.ts
export default defineNuxtConfig({
modules: [
'vue3-carousel-nuxt' // Add the module to your Nuxt configuration
],
carousel: {
prefix: 'MyCustom' // Optional: prefix components to avoid naming conflicts
}
});
// app.vue or a page component (e.g., pages/index.vue)
<template>
<div class="container">
<h1>Featured Items Carousel</h1>
<MyCustomCarousel :items-to-show="1.5" :wrap-around="true" :transition="500">
<MyCustomSlide v-for="slide in 8" :key="slide">
<div class="carousel__item">Item {{ slide }}</div>
</MyCustomSlide>
<template #addons>
<MyCustomNavigation />
<MyCustomPagination />
</template>
</MyCustomCarousel>
</div>
</template>
<style>
.container {
max-width: 900px;
margin: 0 auto;
padding: 20px;
}
.carousel__item {
min-height: 200px;
width: 100%;
background-color: #f0f0f0;
color: #333;
font-size: 24px;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
margin: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
/* Example of overriding default carousel styles */
.carousel__prev, .carousel__next {
background-color: #fff;
border-radius: 50%;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
color: #333;
width: 48px; /* Custom size */
height: 48px; /* Custom size */
}
.carousel__pagination-button--active::after {
background-color: #007bff; /* Custom active pagination dot color */
}
</style>