0

我正在使用 react-cookie 将 cookie 设置为 react

this.props.cookies.set("num_tag", num_tag, {
        expires: midnight
});

我想在 cookie 在午夜过期并且不为空时重置它的值。

4

1 回答 1

0

文档中,您必须将 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});
于 2020-02-28T08:05:45.823 回答