Nuxt Cookie Control


Continuing Dario Ferderber's work on gitlab.com/broj42/nuxt-cookie-control.
🚩 Make sure to read the Migration instructions for all major version updates like v2.0.0, v3.0.0 and following!
Try it out here:
Nuxt.js Cookie Control
🚀 Usage
npm i -D @dargmuesli/nuxt-cookie-control
yarn add -D @dargmuesli/nuxt-cookie-control
pnpm i -D @dargmuesli/nuxt-cookie-control
modules: [
'@dargmuesli/nuxt-cookie-control'
]
modules: [
['@dargmuesli/nuxt-cookie-control', {
}]
]
Components and composables are auto-imported!
<template>
<CookieControl locale="en" />
</template>
<script setup lang="ts">
const {
cookiesEnabled,
cookiesEnabledIds,
isConsentGiven,
isModalActive,
moduleOptions
} = useCookieControl()
</script>
Component Slots
Bar
<CookieControl>
<template #bar>
<h3>Bar title</h3>
<p>Bar description (you can use $cookies.text.barDescription)</p>
<n-link>Go somewhere</n-link>
</template>
</CookieControl>
Modal
<template #modal>
<h3>Modal title</h3>
<p>Modal description</p>
</template>
Cookie
<template #cookie="{config}">
<span v-for="c in config" :key="c.id" v-text="c.cookies"/>
</template>
Props
<CookieControl locale="de"/>
Currently available:
- ar
- de
- en
- es
- fr
- hr
- hu
- it
- ja
- nl
- no
- pt
- ru
- uk
Module Options
barPosition: 'bottom-full',
colors: {
barBackground: '#000',
barButtonBackground: '#fff',
barButtonColor: '#000',
barButtonHoverBackground: '#333',
barButtonHoverColor: '#fff',
barTextColor: '#fff',
checkboxActiveBackground: '#000',
checkboxActiveCircleBackground: '#fff',
checkboxDisabledBackground: '#ddd',
checkboxDisabledCircleBackground: '#fff',
checkboxInactiveBackground: '#000',
checkboxInactiveCircleBackground: '#fff',
controlButtonBackground: '#fff',
controlButtonHoverBackground: '#000',
controlButtonIconColor: '#000',
controlButtonIconHoverColor: '#fff',
modalBackground: '#fff',
modalButtonBackground: '#000',
modalButtonColor: '#fff',
modalButtonHoverBackground: '#333',
modalButtonHoverColor: '#fff',
modalOverlay: '#000',
modalOverlayOpacity: 0.8,
modalTextColor: '#000',
modalUnsavedColor: '#fff',
},
cookies: {
necessary: [],
optional: [],
}
cookieExpiryOffsetMs: 1000 * 60 * 60 * 24 * 365,
cookieNameIsConsentGiven: 'cookie_control_is_consent_given',
cookieNameCookiesEnabledIds: 'cookie_control_cookies_enabled_ids',
isAcceptNecessaryButtonEnabled: true
isControlButtonEnabled: true,
isCookieIdVisible: false,
isCssEnabled: true,
isCssPolyfillEnabled: true,
isDashInDescriptionEnabled: true,
isIframeBlocked: false,
domain: 'yourdomain.com',
locales: ['en'],
localeTexts: {
en: {
save: 'Remember',
}
}
Cookies
Every property the includes a { en: ... }
value is a translatable property that could instead only specify a string ('...'
) or other locales as well ({ de: ..., uk: ... }
).
{
description: {
en: 'Used for cookie control.'
},
id: 'ga',
name: {
en: 'Google Analytics'
},
src: 'https://www.googletagmanager.com/gtag/js?id=<API-KEY>',
targetCookieIds: ['cookie_control_consent', 'cookie_control_enabled_cookies']
}