A Vue.js plugin for manipulating cookies tested up to Vue v2.0.5
Installation
Install through npm
npm install vue-cookie --save
Include in <body>
after loading Vue and it will automatically hook into Vue
Or do it the cool way and load it in your main.js/app.js
// Require dependenciesvar Vue = ;var VueCookie = ;// Tell Vue to use the pluginVue;
Usage
The plugin is available through this.$cookie
in components or Vue.cookie
Rather than implementing my own Cookie handling logic the plugin now wraps the awesome tiny-cookie package
Example
// From some method in one of your Vue componentsthis$cookie;// This will set a cookie with the name 'test' and the value 'Hello world!' that expires in one day// To get the value of a cookie usethis$cookie;// To delete a cookie usethis$cookie;
Advanced examples
// Setting the cookie Domainthis$cookie;// As this cookie is set with a domain then if you wish to delete it you have to provide the domain when calling deletethis$cookie;// Customizing expiresvar date = ;date;this$cookie;this$cookie;this$cookie;this$cookie;this$cookie;this$cookie;this$cookie;this$cookie;this$cookie;
Thanks for using the plugin, I am happy to accept feedback/pull requests, do not forget to star if you like it!
Happy Coding! :D
Tests
This packacge uses the ´´´testemframework and
jasmine``` assertion library
# Run npm install to fetch dependenciesnpm install# Then you may run the tests fromnpm run test-dev