CookieBanner for Nuxt
The consent banner a visitor sees on their first visit.
What it does
Shows on the first visit and stays until the visitor chooses. Under GDPR it offers Accept All, Reject All and Customise; under CCPA it offers Do Not Sell. After a choice it disappears and does not come back in that browser. Its close button hides it for this page view without saving anything; it returns on the next page load, and the recall button appears meanwhile. It shows and hides itself; you only render it.
You already render it if you followed Installation. Try it in the Playground.
In Nuxt, <CookieYesRoot /> renders it for you. To render it yourself, for example to pass it props, list the components inside <CookieYesRoot>: its slot replaces the default contents, so keep the others you need.
<template>
<CookieYesRoot>
<CookieBanner class="my-banner" />
<CookiePreferences />
<RecallButton />
</CookieYesRoot>
<NuxtPage />
</template>Change what it shows
Nothing on the banner is set through props. Everything comes from the cookieyes key in nuxt.config.ts and app/app.config.ts, so the banner, the dialogs and the recall button always match.
| To change | Set |
|---|---|
| The wording, in any language | i18n, see Translations |
| Colours, corner radius, font | theme, see Theme tokens |
| Which buttons appear | regulation: "GDPR" shows Accept / Reject / Customise, "CCPA" shows Do Not Sell |
| The categories behind Customise | categories, see Configuration |
Restyle it
It accepts class and style like any element; they land on the banner card and are added to its own styling, not replacing it. To restyle one part, pass classNames or styles, keyed by part name in camelCase (root, title, description, actions, acceptAll, rejectAll, customise, doNotSell, close, branding), for example :class-names="{ acceptAll: 'my-accept' }". Or use its data-cy-part in your CSS:
[data-cy-part="banner"] {
max-width: 32rem;
}
[data-cy-part="accept-all"] {
font-weight: 600;
}The parts are banner, title, description, actions, accept-all, reject-all, customise, do-not-sell, close and branding. For your own markup, not only your own styles, use the Banner primitives.
Under CCPA
Do Not Sell opens the opt-out dialog, so render it next to the banner:
<CookieYesRoot /> renders it for you whenever a CCPA regulation can apply: regulation: "CCPA", region.strictest: "CCPA" or a "CCPA" value in region.map. If you list the components in its slot yourself, add it there:
<CookieBanner />
<CookieOptOut />Common mistakes
The banner never appears.
You already chose in this browser. Delete the cookieyes-consent cookie and reload.
Do Not Sell does nothing.
<CookieOptOut /> is not rendered.
Next steps
- CookiePreferences: the dialog Customise opens
- RecallButton: lets a visitor change their choice later
- Banner primitives: the same behaviour with your own markup