当前位置:网站首页>JS tool - Cookie simple encapsulation
JS tool - Cookie simple encapsulation
2022-07-27 18:41:00 【V_ AYA_ V】
Just wrap it up cookie Some operation methods of .
/** * @desc according to key Read cookie * @param {String} key * @return {String} cookie */
function getCookie(key) {
const arr = document.cookie.replace(/\s/g, '').split(';')
for (let i = 0; i < arr.length; i++) {
const tempArr = arr[i].split('=')
if (tempArr[0] === key) {
return decodeURIComponent(tempArr[1])
}
}
return ''
}
/** * @desc Set up Cookie * @param {String} key * @param {String} value * @param {Number} days */
function setCookie(key, value, days = 1, path = '/') {
const date = new Date()
date.setDate(date.getDate() + days)
document.cookie = `${
key}=${
value};expires=${
date};path=${
path}`
}
/** * @desc according to key Delete cookie * @param {String} key */
function removeCookie(key) {
// Settings have expired , The system will delete it immediately cookie
setCookie(key, '', -1)
}
export default {
get: getCookie,
set: setCookie,
remove: removeCookie
}
边栏推荐
- MySQL learns the relationship between Day2 Sorting Query / aggregation function / grouping query / paging query / constraint / multiple tables
- [MIT 6.S081] Lab 3: page tables
- 2021.7.30 note index
- [mit 6.s081] LEC 10: multiprocessors and locking notes
- [mit 6.s081] LEC 8: page faults notes
- Random talk on GIS data (V) - geographic coordinate system
- [MIT 6.S081] Lec 8: Page faults 笔记
- 1. OpenCV image basic operation
- 2021.8.1笔记 DBA
- Installation and deployment of zabbix6.0
猜你喜欢
随机推荐
Linked list storage structure of dynamic linked list 2 stack (linkedstack Implementation)
图文结合,完美解释MySQL逻辑备份的实现流程
2021.8.9笔记 request
[mit 6.s081] LEC 10: multiprocessors and locking notes
[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6
2021.7.22 note constraints
rsa加解密(兼容微信小程序环境)
2021.8.1 Notes database design
机器学习——SVM训练集只有一类标签数据而引发的错误
2021.7.12 internal and external connection of notes
一个案例理解mysql视图
2021.7.18笔记 mysql数据类型
2021.8.1笔记 数据库设计
[mit 6.s081] LEC 5: calling conventions and stack frames risc-v notes
Build a simple knowledge question and answer system
Pandas' to_ SQL function usage
[MIT 6.S081] Lab 9: file system
uniapp 在app端page选择器没有效果
An analysis of CPU explosion of a smart logistics WCS system in.Net
2021.7.28 notes









