查看效果请打开调试台查看cookie和console打印日志
mcCookie.set({
key: 'aaa',
val: '111$222#333@444%555*666',
time: '+${1y1m2d}' // 在当前时间的基础上加上指定的年月日时分秒后过期
});
// 同时设置多个并测试特殊字符容错能力
mcCookie.set([
{
key: 'bbb',
val: 'bbb_abc+123+中文+〜!#¥%……&*()',
time: '={2022y6m21d10h0n0s}', // 设置到指定的年月日时分秒时间过期
},
{
key: 'ccc',
val: 'ccc_abc+123+中文+〜!#¥%……&*()',
time: 1665367200000, // 直接指定一个过期时间的时间戳
},
{
key: 'ddd',
val: 'ddd_abc+123+中文+〜!#¥%……&*()',
time: new Date('2025-1-10 10:0:0') // 直接传入一个时间对象
},
]);
let aaa = mcCookie.get('aaa');
console.log(aaa);
let aList = mcCookie.get(['aaa', 'bbb', 'ccc']);
console.log(aList);
let oList = mcCookie.get({a: 'aaa', keyName: 'bbb', abc: 'ccc'});
console.log(oList);
let all = mcCookie.all();
console.log(all);
// 先获取全部cookie
let all = mcCookie.all();
// 我想获取aaa
console.log(all.aaa);
// 还需获取ccc
console.log(all.ccc);
mcCookie.del('aaa');
mcCookie.del(['bbb', 'bbb', 'ddd']);
mcCookie.del('*');
let hasAAA = mcCookie.has('aaa');
console.log(hasAAA);