//存
export const setCookie = (name, value, Days) => {
if (Days == null || Days == '') {
Days = 300
}
var exp = new Date()
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000)
document.cookie = name + '=' + escape(value) + '; path=/;expires=' + exp.toGMTString()
}
//取
export const getCookie = (name) => {
var arr,
reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
arr = document.cookie.match(reg)
if (arr) {
return unescape(arr[2])
} else {
return null
}
}
//删除
export const deleteCookie = (name) => {
setCookie(name, '', -1)
}
//利用JQ添加到指定域下
window.jq.cookie(name,值,{expires: 1, path: '/', domain:域 })
设置存取删除cookie
最新推荐文章于 2021-11-11 11:28:51 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)