//更好的方式:import Cookies from 'js-cookie'
export function delCookie (name) {
let exp = new Date()
exp.setTime(exp.getTime() - 1)
var cval = getCookie(name)
if (cval != null) {
document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
}
}
export function setCookie (name, value, time) {
var exp = new Date()
exp.setTime(exp.getTime() + time * 1)
document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString()
}
export function getCookie (name) {
let arr = document.cookie
let reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
if (arr.match(reg)) {
return unescape(arr[2])
} else {
return null
}
}
网友评论