const Cookie = {
//设置cookie的值
setCookie : function (name,value){
const cookie = document.cookie;
let obj = null;
if(cookie){
obj = JSON.parse(cookie);
}else{
obj = {}
}
obj[${name}
] = value;
document.cookie = JSON.stringify(obj)
},
//获取cookie的值
getCookie : function(name){
const cookie = document.cookie;
if(cookie){
const obj = JSON.parse(cookie);
// console.log(obj)
if(obj.hasOwnProperty(`${name}`)){
return obj[`${name}`]
}
}
return null;
},
//清除cookie的某一个属性的值
removeCookie : function(name){
const cookie = document.cookie;
if(cookie){
const obj = JSON.parse(cookie);
if(obj.hasOwnProperty(`${name}`)){
delete obj[`${name}`]
document.cookie = JSON.stringify(obj)
}
}
},
//清空cookie的值
clearCookie : function(){
document.cookie = JSON.stringify({})
}
}
export default Cookie