写入一个 Cookie 非浏览器环境下静默跳过;key 为空或 value 为 null/undefined 时记录错误并返回
null
undefined
Cookie 名称,不可为空字符串
Cookie 值
Cookie 选项(过期时间、域名、路径等)
setCookie('token', 'abc123')setCookie('sid', 'xyz', { maxAge: 3600, secure: true, sameSite: 'strict' })setCookie('pref', 'dark', { expires: 7 * 24 * 3600 }) // 7 天后过期 Copy
setCookie('token', 'abc123')setCookie('sid', 'xyz', { maxAge: 3600, secure: true, sameSite: 'strict' })setCookie('pref', 'dark', { expires: 7 * 24 * 3600 }) // 7 天后过期
写入一个 Cookie 非浏览器环境下静默跳过;key 为空或 value 为
null/undefined时记录错误并返回