All Projects → cmp-cc → Vue Cookies

cmp-cc / Vue Cookies

Licence: mit
A simple Vue.js plugin for handling browser cookies

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Cookies

Vue Warehouse
A Cross-browser storage for Vue.js and Nuxt.js, with plugins support and easy extensibility based on Store.js.
Stars: ✭ 161 (-45.05%)
Mutual labels:  cookie, cookies
Client-Storage
🗄 Bulletproof persistent Client storage, works with disabled Cookies and/or localStorage
Stars: ✭ 15 (-94.88%)
Mutual labels:  cookie, cookies
cookie-editor
A powerful browser extension to create, edit and delete cookies
Stars: ✭ 245 (-16.38%)
Mutual labels:  cookie, cookies
Ngx Cookie Service
Angular (4.2+ ...11) service for cookies. Originally based on the `ng2-cookies` library.
Stars: ✭ 363 (+23.89%)
Mutual labels:  cookie, cookies
Cookies.js
Simple cookie framework with full Unicode support
Stars: ✭ 254 (-13.31%)
Mutual labels:  cookie, cookies
Cookie Autodelete
Firefox and Chrome WebExtension that deletes cookies and other browsing site data as soon as the tab closes, domain changes, browser restarts, or a combination of those events.
Stars: ✭ 1,015 (+246.42%)
Mutual labels:  cookie, cookies
Zebra Cookie
A ridiculously small (~500 bytes minified) JavaScript API for writing, reading and deleting browser cookies
Stars: ✭ 15 (-94.88%)
Mutual labels:  cookie, cookies
Cookie Universal
Universal cookie plugin, perfect for SSR
Stars: ✭ 376 (+28.33%)
Mutual labels:  cookie, cookies
PolishCookieConsent
Polish Cookie Consent is an extension, which automatically accepts privacy policy/GDPR on websites.
Stars: ✭ 17 (-94.2%)
Mutual labels:  cookie, cookies
cookies
Manage your cookies on client and server side (Angular Universal)
Stars: ✭ 40 (-86.35%)
Mutual labels:  cookie, cookies
Meteor-Cookies
🍪 Isomorphic bulletproof cookie functions for client and server
Stars: ✭ 41 (-86.01%)
Mutual labels:  cookie, cookies
nginx cookie flag module
Module for Nginx which allows to set the flags "HttpOnly", "secure" and "SameSite" for cookies.
Stars: ✭ 101 (-65.53%)
Mutual labels:  cookie, cookies
cookies
Convenient way to use cookies with PSR-7
Stars: ✭ 17 (-94.2%)
Mutual labels:  cookie, cookies
contao-cookiebar
Display the information about cookies on your Contao website
Stars: ✭ 27 (-90.78%)
Mutual labels:  cookie, cookies
CockyGrabber
C# library for the collection of browser information such as cookies, logins, and more
Stars: ✭ 46 (-84.3%)
Mutual labels:  cookie, cookies
gdpr-cookie
Php Cookie checker for Analytics and Tawk.To (GDPR Compliance)
Stars: ✭ 21 (-92.83%)
Mutual labels:  cookie
Auth Boss
🔒 Become an Auth Boss. Learn about different authentication methodologies on the web.
Stars: ✭ 2,879 (+882.59%)
Mutual labels:  cookies
facebook-tool-seller
Facebook Tool Seller Version 1.0.1
Stars: ✭ 25 (-91.47%)
Mutual labels:  cookie
cordova-plugin-wkwebview-inject-cookie
Injects a cookie in order to start the sync processs with wkWebView
Stars: ✭ 43 (-85.32%)
Mutual labels:  cookie
Javascript For Everyone
A step by step guide to learn JavaScript and programming
Stars: ✭ 285 (-2.73%)
Mutual labels:  cookies

vue-cookies

A simple Vue.js plugin for handling browser cookies

Installation

Browser

  <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <script src="https://unpkg.com/[email protected]/vue-cookies.js"></script>

Package Managers

npm install vue-cookies --save

// require
var Vue = require('vue')
Vue.use(require('vue-cookies'))

// es2015 module
import Vue from 'vue'
import VueCookies from 'vue-cookies'
Vue.use(VueCookies)

// set default config
Vue.$cookies.config('7d')

// set global cookie
Vue.$cookies.set('theme','default');
Vue.$cookies.set('hover-time','1s');

Api

syntax format: [this | Vue].$cookies.[method]

  • Set global config
$cookies.config(expireTimes[,path[, domain[, secure[, sameSite]]])  // default: expireTimes = 1d, path = '/', domain = '', secure = '', sameSite = 'Lax'
  • Set a cookie
$cookies.set(keyName, value[, expireTimes[, path[, domain[, secure[, sameSite]]]]])   //return this
  • Get a cookie
$cookies.get(keyName)  // return value                             
  • Remove a cookie
$cookies.remove(keyName [, path [, domain]])  // return this
  • Exist a cookie name
$cookies.isKey(keyName)  // return false or true
  • Get All cookie name
$cookies.keys()  // return a array

Example Usage

set global config

// 30 day after, expire
Vue.$cookies.config('30d')

// set secure, only https works
Vue.$cookies.config('7d','','',true)

// 2019-03-13 expire
this.$cookies.config(new Date(2019,03,13).toUTCString())

// 30 day after, expire, '' current path , browser default
this.$cookies.config(60 * 60 * 24 * 30,'');

support json object

var user = { id:1, name:'Journal',session:'25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX' };
this.$cookies.set('user',user);
// print user name
console.log(this.$cookies.get('user').name)

set expire times

Suppose the current time is : Sat, 11 Mar 2017 12:25:57 GMT

Following equivalence: 1 day after, expire

Support chaining sets together

 // default expire time: 1 day
this.$cookies.set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX")
        // number + d , ignore case
        .set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX","1d")
        .set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX","1D")
        // Base of second
        .set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX",60 * 60 * 24)
        // input a Date, + 1day
        .set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX", new Date(2017, 03, 12))
        // input a date string, + 1day
        .set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX", "Sat, 13 Mar 2017 12:25:57 GMT")

set expire times, input number type

this.$cookies.set("default_unit_second","input_value",1);            // 1 second after, expire
this.$cookies.set("default_unit_second","input_value",60 + 30);      // 1 minute 30 second after, expire
this.$cookies.set("default_unit_second","input_value",60 * 60 * 12); // 12 hour after, expire
this.$cookies.set("default_unit_second","input_value",60 * 60 * 24 * 30); // 1 month after, expire

set expire times - end of browser session

this.$cookies.set("default_unit_second","input_value",0);          // end of session - use 0 or "0"!

set expire times , input string type

Unit full name
y year
m month
d day
h hour
min minute
s second

Unit Names Ignore Case

not support the combination

not support the double value

this.$cookies.set("token","GH1.1.1689020474.1484362313","60s");  // 60 second after, expire
this.$cookies.set("token","GH1.1.1689020474.1484362313","30MIN");  // 30 minute after, expire, ignore case
this.$cookies.set("token","GH1.1.1689020474.1484362313","24d");  // 24 day after, expire
this.$cookies.set("token","GH1.1.1689020474.1484362313","4m");  // 4 month after, expire
this.$cookies.set("token","GH1.1.1689020474.1484362313","16h");  // 16 hour after, expire
this.$cookies.set("token","GH1.1.1689020474.1484362313","3y");  // 3 year after, expire

// input date string 
this.$cookies.set('token',"GH1.1.1689020474.1484362313", new Date(2017,3,13).toUTCString());
this.$cookies.set("token","GH1.1.1689020474.1484362313", "Sat, 13 Mar 2017 12:25:57 GMT ");

set expire support date

var date = new Date;
date.setDate(date.getDate() + 1);
this.$cookies.set("token","GH1.1.1689020474.1484362313", date);

set never expire

this.$cookies.set("token","GH1.1.1689020474.1484362313", Infinity);  // never expire
// never expire , only -1,Other negative Numbers are invalid
this.$cookies.set("token","GH1.1.1689020474.1484362313", -1); 

remove cookie

this.$cookies.set("token",value); // domain.com and *.doamin.com are readable
this.$cookies.remove("token"); // remove token of domain.com and *.doamin.com 

this.$cookies.set("token", value, null, null, "domain.com"); // only domain.com are readable
this.$cookies.remove("token", null, "domain.com"); // remove token of domain.com 

set other arguments

// set path
this.$cookies.set("use_path_argument","value","1d","/app");  

// set domain
this.$cookies.set("use_path_argument","value",null, null, "domain.com");   // default 1 day after,expire

// set secure
this.$cookies.set("use_path_argument","value",null, null, null,true);

// set sameSite - should be one of `None`, `Strict` or `Lax`. Read more https://web.dev/samesite-cookies-explained/
this.$cookies.set("use_path_argument","value",null, null, null, null, "Lax");

other operation

// check a cookie exist
this.$cookies.isKey("token")

// get a cookie
this.$cookies.get("token");

// remove a cookie
this.$cookies.remove("token");

// get all cookie key names, line shows
this.$cookies.keys().join("\n"); 

// remove all cookie
this.$cookies.keys().forEach(cookie => this.$cookies.remove(cookie))

// vue-cookies global
[this | Vue].$cookies.[method] 

Warning

$cookies key names Cannot be set to ['expires','max-age','path','domain','secure','SameSite']

License

MIT Copyright (c) 2016-present, cmp-cc

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].