You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Or do it the cool way and load it in your main.js/app.js
// Require dependenciesvarVue=require('vue');varVueCookie=require('vue-cookie');// Tell Vue to use the pluginVue.use(VueCookie);
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.set('test','Hello world!',1);// 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.get('test');// To delete a cookie usethis.$cookie.delete('test');
Advanced examples
// Setting the cookie Domainthis.$cookie.set('test','Random value',{expires: 1,domain: 'localhost'});// 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.delete('test',{domain: 'localhost'});// Customizing expiresvardate=newDate;date.setDate(date.getDate()+21);this.$cookie.set('dateObject','A date object',{expires: date});this.$cookie.set('dateString','A parsable date string',{expires: date.toGMTString()});this.$cookie.set('integer','Seven days later',{expires: 7});this.$cookie.set('stringSuffixY','One year later',{expires: '1Y'});this.$cookie.set('stringSuffixM','One month later',{expires: '1M'});this.$cookie.set('stringSuffixD','One day later',{expires: '1D'});this.$cookie.set('stringSuffixh','One hour later',{expires: '1h'});this.$cookie.set('stringSuffixm','Ten minutes later',{expires: '10m'});this.$cookie.set('stringSuffixs','Thirty seconds later',{expires: '30s'});
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 andjasmine``` assertion library
# Run npm install to fetch dependencies
npm install
# Then you may run the tests from
npm run test-dev