gpt4 book ai didi

javascript - react-cookie 无法设置过期或 maxAge

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:21:06 42 4
gpt4 key购买 nike

我似乎无法使用 react-cookie 设置 cookie 的过期时间...这是我的设置:

import { Cookies } from 'react-cookie'
const cookies = new Cookies()
import moment from 'moment'

以下尝试均失败:

cookies.set('cookieName', {key: value}, {path: '/', expires: new Date(Date.now()+2592000)})
cookies.set('cookieName', {key: value}, {path: '/', expires: moment().add(30, "days")})
cookies.set('cookieName', {key: value}, {path: '/', maxAge: 2592000})

Chrome 继续呈现:

Expires
When the browsing session ends

最佳答案

react-cookie 中的 Cookies 似乎已移至 universal-cookie 包中。所以以下应该有效:

import Cookies from 'universal-cookie';

const cookies = new Cookies();
cookies.set('cookieName', {key: value}, {path: '/', expires: new Date(Date.now()+2592000)});

关于javascript - react-cookie 无法设置过期或 maxAge,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47860326/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com