reactjs - 有没有办法使用 react-cookie 在午夜过期时为 cookie 设置默认值?
问题描述
我正在使用 react-cookie 将 cookie 设置为 react
this.props.cookies.set("num_tag", num_tag, {
expires: midnight
});
我想在 cookie 在午夜过期并且不为空时重置它的值。
解决方案
从文档中,您必须将 expires 设置为绝对日期。
所以你可以做的是获取当前日期,添加一天,然后将时间推到午夜。
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
this.props.cookies.set('num_tag', num_tag, {expires: tomorrow});
推荐阅读
- python - 如何根据第二列中的值计算一列的平均值?
- mysql - 如何在用户定义的函数中将数据库列作为参数传递?
- java - 在服务端不添加跨域代码如何解决跨域问题?
- ios - Cut UIImage from UIView Mask
- java - parentActivityName 是一个片段
- python - python 3 替换 fpformat.fix()
- android - Android Q 后台限制
- xaml - Xamarin Forms Flex Layout 大小问题
- flutter - 如何通过飞镖中的另一个项目列表搜索对象列表
- javascript - 类型化数组和联合类型