保存cookie后提取出来发现字符串是被编码过的,需要decodeURIComponent进行下解码才可以
设置cookie
setCookie(c_name, value, expiredays) { let exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}
删除cookie,设置一个已经过期的expires
delCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); }