Created
July 24, 2017 16:56
-
-
Save daliborgogic/ac0c1ac51c98e24b98b79662bec9a956 to your computer and use it in GitHub Desktop.
Get, set, delete cookie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const setCookie = (name, value, days = 7, path = '/') => { | |
const expires = new Date(Date.now() + days * 864e5).toUTCString() | |
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=${path}` | |
} | |
const getCookie = name => { | |
return document.cookie.split('; ').reduce((r, v) => { | |
const parts = v.split('=') | |
return parts[0] === name ? decodeURIComponent(parts[1]) : r | |
}, '') | |
} | |
const deleteCookie = (name, path) => setCookie(name, '', -1, path) | |
// setCookie('token', this.$store.state.token, 10, this.$route.path) | |
// getCookie('token') | |
// deleteCookie('token') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment