vue-cookieconsent

A Vue plugin, that wraps the awesome `cookieconsent` library.
6,728 16
Install
npm install vue-cookieconsent
Latest Version:0.0.11
License:MIT
Last Updated:Oct 22, 2022
Links: GitHub  ·  npm
Maintainer: eyecatchup

vue-cookieconsent

A Vue plugin that wraps the awesome Cookieconsent library.

Note: A Vue 2 compatible plugin will be published as vue2-cookieconsent soon.


Cookie Consent cover


Install

Run npm install vue-cookieconsent.

Setup

In your main.[js|ts]:

import CookieConsent from 'vue-cookieconsent'

import '../node_modules/vue-cookieconsent/vendor/cookieconsent.css'
//import './theme/cookieconsent_custom.css' // custom cookie consent styles

// See: https://github.com/orestbida/cookieconsent#all-configuration-options
const consentOptions = {}

const app = createApp(App)
  .use(CookieConsent, consentOptions)
  .use(router);

Usage

The Cookieconsent instance is globally available via this.$cc, providing the full library API. See the Cookieconsent API documentation for all available methods.

To hook into the library's event callbacks, there's an additional on method, which can be used in your Vue components to register a handler to be executed whenever the consent settings change.

export default defineComponent({
    name: 'Foo',
    beforeCreate () {
        this.$cc.on('consent-changed', () => {
            console.log('cookie consent changed, new user preferences:', 
                this.$cc.getUserPreferences())
            // your business logic..
        })
    }
})

Related Packages

@zeste/vue

Vue 3 bindings for zeste: reactive consent state, headless components, SSR-ready...

318 2
@websideproject/nuxt-cookie-consent

GDPR cookie and cookieless-tracking consent for Nuxt 4: banner, floating button,...

451 1
@theplaintheory/vue

Vue 3 and Nuxt bindings for Plain Theory consent: plugin, useConsent composable...

146 0
@performing/cookie-popup-gdpr

Simple and easy to use cookie popup for GDPR compliance

1,088 1
@allomambo/galletita

Extra simple privacy policy solution

4,509

Version History

Version Released License
0.0.11 MIT
0.0.10 MIT
0.0.9 MIT
0.0.8 MIT
0.0.7 MIT