本文共 1086 字,大约阅读时间需要 3 分钟。
Use the Response.cookie()
method to manipulate your cookies.
使用Response.cookie()
方法来操作您的cookie。
Examples:
例子:
res.cookie('username', 'Flavio')
This method accepts a third parameter, which contains various options:
此方法接受第三个参数,其中包含各种选项:
res.cookie('username', 'Flavio', { domain: '.flaviocopes.com', path: '/administrator', secure: true })res.cookie('username', 'Flavio', { expires: new Date(Date.now() + 900000), httpOnly: true })
The most useful parameters you can set are:
您可以设置的最有用的参数是:
Value | Description |
---|---|
domain | The |
expires | Set the . If missing, or 0, the cookie is a session cookie |
httpOnly | Set the cookie to be accessible only by the web server. See |
maxAge | Set the expiry time relative to the current time, expressed in milliseconds |
path | The . Defaults to ‘/’ |
secure | Marks the |
signed | Set the cookie to be signed |
sameSite | Value of |
值 | 描述 |
---|---|
domain | |
expires | 设置 。 如果丢失或为0,则该cookie是会话cookie |
httpOnly | 将cookie设置为只能由Web服务器访问。 参见 |
maxAge | 设置相对于当前时间的到期时间,以毫秒为单位 |
path | 。 默认为'/' |
secure | 将标记为 |
signed | 设置要签名的cookie |
sameSite | 价值 |
A cookie can be cleared with:
Cookie可以通过以下方式清除:
res.clearCookie('username')
翻译自:
转载地址:http://uxqgb.baihongyu.com/