Tutorial

Handle the EU Cookie Law in Vue.js with vue-cookie-law

Published on May 15, 2017
Default avatar

By Joshua Bemenderfer

Handle the EU Cookie Law in Vue.js with vue-cookie-law

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Developers in the EU are probably fairly familiar with the Cookie Law, the law requiring you to inform users if your website uses cookies and have them accept that or leave the site. Now, it’s just a tiny bit of extra effort to implement something like that, but why do it yourself if someone else already has? (The classic open-source lazy escape hatch.) <3

Thanks to vue-cookie-law, you can have a full EU Cookie Law component attached to the top or bottom of your website’s viewport in just a few lines of code. Easy-peasy!

Installation

Install vue-cookie-law via. Yarn or NPM.

# Yarn
$ yarn add vue-cookie-law
# NPM
$ npm install vue-cookie-law --save

Usage

The most basic usage of vue-cookie-law would be as follows:

<template>
  <div class="main-wrapper">
    <cookie-law theme="blood-orange--rounded"></cookie-law>
  </div>
</template>

<script>
import CookieLaw from 'vue-cookie-law';

export default {
  components: {
    CookieLaw
  }
}
</script>

Customization

vue-cookie-law has a few props you can customize, including:

  • buttonText - Change the text on the acceptance button.
  • message - The message displayed to your users when they first visit. The default is This website uses cookies to ensure you get the best experience on our website.
  • theme - The theme of the component. Six themes are included by default, and additional ones may be created easily with CSS as shown below.
  • position - top or bottom.
  • transitionName - The transition used to hide and show the notice. Currently supports slideFromBottom, slideFromTop, and fade.

Theming:

You can create custom themes for vue-cookie-law simply by wrapping all your classes with .Cookie–themeName Then just pass your theme’s name with <vue-cookie-law theme="themeName"></vue-cookie-law>.

Example: (Batman-style)

.Cookie--batman {
  background: black;

  > .Cookie__button {
      background: black;
      color: yellow;
  }

  > .Cookie__message {
    color: yellow;
  }
}

There you go! Have fun complying!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
Joshua Bemenderfer

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Has been there any change to the Cookie-Law in the EU? Is there something else i have to do, to be up to date?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel