设置cookie
//name 字段名 value 字段值 perpetual 有效期
setCookie(name,value,perpetual) {
let exdate = new Date()
exdate.setDate(exdate.getDate() + perpetual) //exdate.setDate(exdate.getDate() + 365)
document.cookie = name + '=' + value + ';expires=' + exdate.toGMTString()
//永久有效
//document.cookie = name + '=' + value + ';expires=' + 'Fri, 31 Dec 9999 23:59:59 GMT'
},
获取cookie数据
//name 字段名
getCookie (name) {
if (document.cookie.length > 0) {
var start = document.cookie.indexOf(name + '=')
if (start !== -1) {
start = start + name.length + 1
let end = document.cookie.indexOf(';', start)
if (end === -1) end = document.cookie.length
return unescape(document.cookie.substring(start, end))
}
}
return ''
},