设置cookie
setCookie(name, value, days) { // days为保存时间长度
var date = new Date()
date.setDate(date.getDate()+days)
document.cookie = name+'='+value+';expires='+date;
},
获取cookie
getCookie(name) {
var arr = document.cookie.split(';');
for(var i=0;i<arr.length;i++) {
var arr2=arr[i].split('=');
if(arr2[0]===name) {
return arr2[1]
}
}
return ''
},
删除cookie
removeCookie(name) {
setCookie(name, 1, -1) // -1代表昨天过期,系统自动删除
},
修改cookie
changeCookie() {
document.cookie = 'password=1234'
}