Module: cookie

本模块提供 cookie 读写方法。
Source:

Methods

(static) get(name) → {string}

读取 cookie。
Parameters:
Name Type Description
name string cookie 名。
Author:
  • luoliquan
Source:
Returns:
cookie 值。
Type
string
Example
cookie.get('a');

(static) remove(name, optionsopt)

移除 cookie。
Parameters:
Name Type Attributes Description
name string cookie 名。
options Object <optional>
参数。
Properties
Name Type Attributes Description
domain string <optional>
所在域。
path string <optional>
所在路径。
Author:
  • luoliquan
Source:
Example
remove('a');
remove('b' {
  domain: '.polyv.net',
  path: '/abc'
})

(static) set(key, value, optionsopt)

写入 cookie。
Parameters:
Name Type Attributes Description
key string cookie 键。
value string cookie 值。
options Object <optional>
参数。
Properties
Name Type Attributes Description
domain string <optional>
所在域。
path string <optional>
所在路径。
expires Date | number | string <optional>
过期时间。 为日期类型时表示绝对时间; 为数字(单位毫秒)时表示相对时间(当前时间+相对值); 为字符串时表示相对时间(当前时间+相对值),支持格式包括(%表示数字): %secs, %mins, %hours, %days, %months, %years。
secure boolean <optional>
是否只在 https 连接中有效。
sameSite string <optional>
访问限制:Lax、Strict 或 None。
Author:
  • luoliquan
Source:
Example
cookie.set('a', '1')
cookie.set('b', '2', {
  expires: '6months', // 180 天
  domain: '.polyv.net',
  path: '/'
});