Skip to content
Getting StartedInstallation

Installation for Vue

Markdown
Loading…

Install the CookieYes SDK and get a working banner in three steps.

Three steps, about five minutes: install the package, add the plugin to your app, and render the banner once. If you would rather have the files written for you, run npx @cookieyes/cli init: it does exactly what this page does. See Quick start.

Prerequisites

RequirementMinimum
Node.js20
Vue3.5

1. Install

npm install @cookieyes/vue

This is the only package you install. vue is a peer dependency, so the copy your app already has is the one used.

2. Add the plugin

One file: the configuration and the stylesheet.

src/consent-manager.ts
import type { App } from "vue";
import { CookieYes, type CookieYesConfig } from "@cookieyes/vue";
import "@cookieyes/vue/styles.css";

const config: CookieYesConfig = {
  mode: "cookie-only", // no backend needed
  regulation: "GDPR", // "GDPR" | "CCPA"
};

export function setupConsent(app: App): void {
  app.use(CookieYes, config);
}

app.use(CookieYes, config) takes the same configuration as initCookieYes() in the other packages, so a configuration copies across unchanged.

The stylesheet import is required. The components ship no inline styling, so without it they render as plain text, with no error to tell you why.

3. Render it once

Call setupConsent before the app mounts:

src/main.ts
import { createApp } from "vue";
import App from "./App.vue";
import { setupConsent } from "./consent-manager";

const app = createApp(App);
setupConsent(app);
app.mount("#app");

A component renders the banner, the preferences dialog and the recall button:

src/components/CookieYesRoot.vue
<script setup lang="ts">
import { CookieBanner, CookiePreferences, RecallButton } from "@cookieyes/vue";
</script>

<template>
  <CookieBanner />
  <CookiePreferences />
  <RecallButton />
</template>

Put it before your page content, so the banner is early in the DOM: screen readers announce it first, and it paints before the rest of the page.

src/App.vue
<script setup lang="ts">
import CookieYesRoot from "./components/CookieYesRoot.vue";
</script>

<template>
  <CookieYesRoot />
  <h1>Your app</h1>
</template>

Done. Reload the page and the banner appears. If it does not, see Common mistakes.

Common mistakes

The banner renders as unstyled text. The stylesheet import is missing. Keep the @cookieyes/vue/styles.css import in consent-manager.ts, where the example above has it.

A CookieYes component or composable throws "could not find CookieYes". app.use(CookieYes, config) has not run on the app that renders it. Call setupConsent(app) before app.mount(), as in step 3, and call composables inside setup().

Nothing renders: no banner, no error anywhere. <CookieYesRoot /> is not rendered by any component. Render it once, as in step 3.

Next steps

  • Configuration: every option the plugin takes, including CCPA and languages
  • Integrations: load Google Analytics, Meta Pixel and other tags only after consent
  • Styling: match the banner to your brand

On this page