[英]Cookies.set doesn't set the value in cookie (js-cookie)
I'm trying to set the some data inside of cookie using js-cookie.我正在尝试使用 js-cookie 在 cookie 中设置一些数据。 but somehow it's not setting in the cookie.但不知何故,它没有在 cookie 中设置。 following is my code:以下是我的代码:
const setCookie = (name: string, value: string, expires: Date) => {
Cookies.set(name, value, {expires})
}
and this is the result when I console.log this line:这是我 console.log 这一行时的结果:
UserId=1; path=/; expires=Thu, 09 Apr 2020 15:26:37 GMT
I thought that path=/ is the problem, so I've tried to set the path as well, but didn't work.我认为 path=/ 是问题所在,所以我也尝试设置路径,但没有奏效。 Does anyone have idea why is not setting into the cookie?有谁知道为什么不设置到cookie中?
Updated: data passed to name, value, expires are:更新:传递给名称、值、过期的数据是:
UserId, 1, Thu Apr 09 2020 11:26:37 GMT-0400 (Eastern Daylight Time) UserId,1,2020 年 4 月 9 日星期四 11:26:37 GMT-0400(东部夏令时间)
Expires parameter should be a number which indicate how much days until your cookie will expire Expires 参数应该是一个数字,表示您的 cookie 将过期的天数
just update your function as follow只需更新您的 function 如下
const setCookie = (name: string, value: string, expires: number) => {
Cookies.set(name, value, {expires})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.