1.1.4 • Published 8 years ago

vue-cookie v1.1.4

Weekly downloads
27,844
License
MIT
Repository
github
Last release
8 years ago

vue-cookie CircleCI

A Vue.js plugin for manipulating cookies tested up to js 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

<script src="/node_modules/vue-cookie/build/vue-cookie.js'"></script>

Or do it the cool way and load it in your main.js/app.js

// Require dependencies
var Vue = require('vue');
var VueCookie = require('vue-cookie');
// Tell Vue to use the plugin
Vue.use(VueCookie);

Usage

The plugin is available through this.$cookie in components or js.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 components
this.$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 use
this.$cookie.get('test');

// To delete a cookie use
this.$cookie.delete('test');
Advanced examples
// Setting the cookie Domain
this.$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 delete
this.$cookie.delete('test', {domain: 'localhost'});

// Customizing expires
var date = new Date;
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
dltuiweb-client-templateabpx-coretemplate-firm-pc0wenchao-vue@infinitebrahmanuniverse/nolb-vue-cowbu-design-system@everything-registry/sub-chunk-3077gc-bwp-web-uit-httpt-zip-filewl-vuevue-auth0-handlervue-auth-laravelwevue-toolstemplate-firm-pc-modeltemplate-firm-pcthai-website-staticvma-assistvue-component-tablevma-vue-assistvue-em-uivue-element-web-assetvue-element-assistvue-egg-frameworkvmes-flowable2vmes-flowable3vue-assistvue-demo-test@dreampie/vue2-components@dreampie/vue2-plugin@cwamodules/core@bwstarter/coreform-design-web-cesgenerate-ui-templategc-starter-plugin-learn-uigc-starter-uieip-admin-uigc-starter-ui-plusitz-elementjj-chestnutzebra-vuecli3-mtydigife-libraryuma-unimax-mesuma-unimax-webtopological-constructortopmdrt-city-pickerut-plt-systemmgtut-plt-systemtestut-plt-taskmgtut-plt-workflowut-plt-xformmgtut-plt-hrmmgttimi-vue-web-assetvue-phoenixxye-test2zhlceszhuifengzhe-pc-uizui-plugzy_pmsvuejs-quizvue-y01vue-svpw-umd-testunimax-web-depzmax-company-components@gcpaas/api-ui@gcpaas/core-ui@gcpaas/job-ui@nodopiano/buzz-vox@mkplace/mkplace-vue@kaoyaya/kyy-com@moreillon/vue_authentication_wall@moreillon/vue_authentication_wall_vuetify@moreillon/vue_application_template@moreillon/vue_application_template_vuetify@sc-voice/scv-staticmonitor-componentsmicroba-questionnairepackage-ftmsnutter-uipaperchecksc-voicerd-maprui-m-navrui-m-headerq-zip-fileproduct-sub-view-templateproduct-task-viewproduct-template-viewproduct-yun-sample-viewproduct-yun-task-viewproduct-yun-entrust-viewproduct-yun-quote-viewproduct-yun-report-viewproduct-yun-resource-viewproject-ftmsnetforce_themephzjhbasicphwebs-cookiebar
1.1.4

8 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.0.0

9 years ago