Skip to content

Installation

Getting Nuxt Keen Slider running takes two steps: add the module, then build a slider with the auto-imported useKeenSlider() composable. There’s no component to mount and no stylesheet to import — the module handles both.

The quickest way is the Nuxt CLI, which installs the package and adds it to your nuxt.config for you:

Terminal window
npx nuxi@latest module add nuxt-keen-slider

If you’d rather install it by hand, add the package with your preferred package manager:

Terminal window
# pnpm
pnpm add nuxt-keen-slider
Terminal window
# npm
npm install nuxt-keen-slider
Terminal window
# yarn
yarn add nuxt-keen-slider

Then add 'nuxt-keen-slider' to the modules array in nuxt.config.ts:

export default defineNuxtConfig({
modules: ['nuxt-keen-slider'],
})

The module auto-imports the useKeenSlider() composable, so you can use it in any component without an import line. It returns a tuple: a template ref for the container, and a ref to the slider instance.

Create a component anywhere in your app — for example components/MySlider.vue:

<template>
<div ref="container" class="keen-slider">
<div class="keen-slider__slide">1</div>
<div class="keen-slider__slide">2</div>
<div class="keen-slider__slide">3</div>
</div>
</template>
<script setup>
const [container] = useKeenSlider({
loop: true,
slides: {
perView: 2,
spacing: 15,
},
})
</script>

Two pieces of markup are required:

  • The container element must carry the keen-slider class and the ref returned by the composable.
  • Each slide must be a direct child carrying the keen-slider__slide class.

Then drop the component into a page:

<template>
<MySlider />
</template>

That’s it — you now have a working, touch-enabled carousel.

You don’t have to import any stylesheet. The module adds keen-slider/keen-slider.css to nuxt.options.css for you, so the slider is styled correctly out of the box. It also adds keen-slider to build.transpile so the package works under Nuxt’s server-side rendering.

  • Usage — the slider instance, navigation, dots, and events.
  • Configuration — every option you can pass to useKeenSlider().