Components & overriding

The built-in components and how to replace them.

Components & overriding

The module ships three globally-registered components:

ComponentRole
CookieConsentBannerThe initial bottom banner shown on first visit (when required).
CookieConsentModalThe detailed settings dialog (desktop) / drawer (mobile).
CookieConsentFabA floating button to reopen settings after a choice is made.

Add them once, typically in app.vue:

<template>
  <div>
    <NuxtPage />
    <CookieConsentBanner />
    <CookieConsentModal />
    <CookieConsentFab />
  </div>
</template>

Styling

The built-in components are plain CSS (scoped styles, an inline SVG icon) with no UI framework, Tailwind or icon library behind them, so they work in any app. Their colours come from the colors option as CSS variables, and from darkColors under a .dark ancestor — the class Nuxt's color mode (and Nuxt UI) puts on <html>. To match your own UI kit (e.g. @nuxt/ui), override them — see below.

Overriding

Thanks to Nuxt's component resolution, you can replace any built-in component by creating a file with the same name in your project's components/ directory:

components/
  CookieConsentBanner.vue
  CookieConsentModal.vue
  CookieConsentFab.vue

Your version takes precedence: the module registers its defaults with a negative priority. Use the component composables to keep all the consent logic while supplying your own markup:

components/CookieConsentBanner.vue
<script setup lang="ts">
const { isVisible, acceptAll, customize } = useConsentBanner()
</script>

<template>
  <div v-if="isVisible" class="my-banner">
    <p>
      <template v-for="part in useConsentText('bannerDescription')" :key="part.content">
        <a v-if="part.type === 'link'" :href="part.href">{{ part.content }}</a>
        <span v-else>{{ part.content }}</span>
      </template>
    </p>
    <button @click="customize">{{ useConsentText('customizeBtn')[0].content }}</button>
    <button @click="acceptAll">{{ useConsentText('acceptAllBtn')[0].content }}</button>
  </div>
</template>

apps/playground/examples/overrides/ in this repository has overrides of all three — a good starting point.

Need a Landing Page?

Modern landing pages with optional modules (blog, docs, forms, i18n). Let's discuss your project.

Build Your MVP

Full-stack SaaS development. Expert in database design, multi-tenancy, and scalable architecture.

Deployment Help

Dockerize your backend, set up CI/CD pipelines, deploy to Cloudflare or Hetzner. Early-stage setup.

Suggest a SaaS Tool

Missing a calculator or tool? Suggest what you'd like to see on our site.