import Cookies from 'vue-cookies'; const cookies = {}; cookies.set = function (name = 'default', value = '', cookieSetting = 60 * 60 * 24 * 365) { Cookies.set(`MRGCY_${name}`, value, cookieSetting); }; cookies.get = function (name = 'default') { return Cookies.get(`MRGCY_${name}`); }; /** * @description 拿到 cookie 全部的值 */ cookies.getAll = function () { return Cookies.get(); }; cookies.remove = function (name = 'default') { return Cookies.remove(`MRGCY_${name}`); }; cookies.clean = function () { let prefix = 'MRGCY_' ; Cookies.keys().forEach(cookie => { if (cookie.indexOf(prefix) !== -1) { Cookies.remove(cookie); } }); }; export default cookies;
设置当天23:59:59过期
var curDate = new Date(); //当前时间戳 var curTamp = curDate.getTime(); //当日凌晨的时间戳,减去一毫秒是为了防止后续得到的时间不会达到00:00:00的状态 var curWeeHours = new Date(curDate.toLocaleDateString()).getTime() - 1; //当日已经过去的时间(毫秒) var passedTamp = curTamp - curWeeHours; //当日剩余时间 var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTime = new Date(); leftTime.setTime(leftTamp + curTamp); cookies.set('home_daily_strip', 'close', leftTime.toGMTString());
标签:function,cookies,vue,name,Cookies,用法,60,var From: https://www.cnblogs.com/zhenfeng25/p/17265951.html