当前位置:网站首页>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
}
边栏推荐
- Solve the problem of JSP cascading
- 机器学习分类任务效果评估指标大全(包含ROC和AUC)
- Build a simple knowledge question and answer system
- uniapp 在app端page选择器没有效果
- [MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6
- [MIT 6.S081] Lab 3: page tables
- Deep learning: GCN (graph convolution neural network) theory learning summary
- Error launching IDEA
- Nowcoder (5 choices)
- 微信小程序获取手机号
猜你喜欢

Must the MySQL query column be consistent with the group by field?

2021.7.12 internal and external connection of notes

Knowledge map pyhanlp realizes named body recognition (with named body recognition code)

multi-table query

Class not found: "the com.parkmanagement.dao.daotest test cannot find the test class
![[mit 6.s081] LEC 9: interrupts notes](/img/b6/a8d39aa7ede4eb1c5a74e6d15b3b1c.png)
[mit 6.s081] LEC 9: interrupts notes

2021.8.7 note Servlet
![[MIT 6.S081] Lab8: locks](/img/9f/0ff7a0226837a3c420f49e6da8209f.png)
[MIT 6.S081] Lab8: locks
![[MIT 6.S081] Lab 9: file system](/img/f5/ea30b1fe5b6d73c86f2509c690ca20.png)
[MIT 6.S081] Lab 9: file system

2021.7.13 note sub query
随机推荐
10 SQL optimization schemes summarized by Alibaba P8 (very practical)
机器学习——SVM训练集只有一类标签数据而引发的错误
XML learning Day1: XML / jsup parser / selector /xpath selector
搭建一个简单的知识问答系统
Chained storage structure of dynamic linked list 3 queue (linkedqueue Implementation)
Generate PDM file from Navicat export table
The second parameter of fragmenttransaction.replace reports an error
微信小程序 wxacode.getUnlimited生成小程序码
Wechat applet wxacode.getunlimited generates applet code
I was forced to optimize the API gateway query interface
[mit 6.s081] LEC 8: page faults notes
2021.7.13 note sub query
Log4j 史诗级漏洞,京东这样的大厂都中招了
[MIT 6.S081] Lab 7: Multithreading
Visual Studio Code安装教程(超详细)
Must the MySQL query column be consistent with the group by field?
Why don't you like it? It's easy to send mail in ci/cd
[MIT 6.S081] Lec 4: Page tables 笔记
[MIT 6.S081] Lec 1: Introduction and examples 笔记
MySQL学习 Day3 多表查询 / 事务 / DCL