当前位置:网站首页>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
}
边栏推荐
- 使用jieba、pyhanlp工具实现关键字词句的提取
- 10 SQL optimization schemes summarized by Alibaba P8 (very practical)
- Chained storage structure of dynamic linked list 3 queue (linkedqueue Implementation)
- Lotcode dynamic array exercise (724118766)
- Dynamic linked list 4 one-way circular linked list (loopsingle Implementation)
- 2021.7.17笔记 mysql其他命令
- Linked list storage structure of dynamic linked list 2 stack (linkedstack Implementation)
- MySQL学习 Day1 DDL、DML、DQL基础查询
- [MIT 6.S081] Lab 10: mmap
- MySQL 主从复制数据不一致,怎么办?
猜你喜欢
随机推荐
Conflict between blur event and click event in input box
uniapp运行到手机(真机调试)
2021.8.7 note Servlet
怎么会不喜欢呢,CI/CD中轻松发送邮件
你有没有在MySQL的order by上栽过跟头
RSA encryption and decryption (compatible with wechat applet environment)
Visual Studio Code安装教程(超详细)
Wechat applet multi file upload
MySQL basic statement
Deep learning - VIDEO behavior recognition: paper reading - two stream revolutionary networks for action recognition in videos
[MIT 6.S081] Lec 1: Introduction and examples 笔记
Solve the problem of JSP cascading
2021.7.19 notes DML
MySQL学习 Day3 多表查询 / 事务 / DCL
[mit 6.s081] LEC 9: interrupts notes
I was forced to optimize the API gateway query interface
Run the uniapp to the mobile phone (real machine debugging)
MySQL 主从复制数据不一致,怎么办?
uniapp H5跨域问题
[MIT 6.S081] Lab 10: mmap









