当前位置:网站首页>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
}
边栏推荐
- 2021.8.7笔记 servlet
- 2021.7.22 note constraints
- Build a simple knowledge question and answer system
- 2021.8.9笔记 request
- 2021.8.1笔记 数据库设计
- Using Jieba and pyhanlp tools to extract keyword words and sentences
- [mit 6.s081] LEC 1: introduction and examples notes
- 机器学习分类任务效果评估指标大全(包含ROC和AUC)
- Solve the problem of JSP cascading
- C杂讲 链表初讲
猜你喜欢

Chained storage structure of dynamic linked list 3 queue (linkedqueue Implementation)
![[mit 6.s081] LEC 4: page tables notes](/img/30/f1e12d669b656a0b14aa8c7b210085.png)
[mit 6.s081] LEC 4: page tables notes

Installation and deployment of zabbix6.0

「MySQL那些事」一文详解索引原理

Deep learning - paper reading: action structural graph convolution network as-gcn
![[MIT 6.S081] Lab 5: xv6 lazy page allocation](/img/f6/8b619412bc6ba425d0f04629917e80.png)
[MIT 6.S081] Lab 5: xv6 lazy page allocation

The combination of text and words perfectly explains the implementation process of MySQL logical backup
![[mit 6.s081] LEC 10: multiprocessors and locking notes](/img/62/ca6362830321feaf450865132cdea9.png)
[mit 6.s081] LEC 10: multiprocessors and locking notes

2021.8.1笔记 数据库设计

Using Jieba and pyhanlp tools to extract keyword words and sentences
随机推荐
你有没有在MySQL的order by上栽过跟头
Log4j 史诗级漏洞,京东这样的大厂都中招了
2021.8.6 notes jsoup
2021.7.28 notes
搭建一个简单的知识问答系统
Visual studio code installation tutorial (super detailed)
MySQL查询列必须和group by字段一致吗?
Visual Studio Code安装教程(超详细)
Deep learning: Gan case exercise -minst handwritten digits
机器学习——SVM训练集只有一类标签数据而引发的错误
[MIT 6.S081] Lab 3: page tables
pandas的to_sql函数使用
机器学习分类任务效果评估指标大全(包含ROC和AUC)
2021.8.1 Notes database design
2021.7.30笔记 索引
Knowledge map pyhanlp realizes named body recognition (with named body recognition code)
Alibaba architects spent 280 hours sorting out 1015 pages of distributed full stack pamphlets to easily start the distributed system
uniapp 在app端page选择器没有效果
Deep learning - VIDEO behavior recognition: paper reading - two stream revolutionary networks for action recognition in videos
Wechat applet obtains mobile number