js-cookie

安装: 

  npm i js-cookie

  import Cookies from 'js-cookie'

 

具体用法:

写入:
  Cookies.set('name', 'value');   Create a cookie that expires 7 days from now, valid across the entire site:   Cookies.set('name', 'value', { expires: 7 });

    创建一个过期的cookie,该cookie对当前页的路径有效:

  Cookies.set('name', 'value', { expires: 7, path: '' });
  
获取:
  Cookies.get('name'); // => 'value'   Cookies.get('nothing'); // => undefined   获取所有cookie   Cookies.get(); // => { name: 'value' }

删除:   Cookies.remove('name');
  删除对当前页路径有效的cookie:     Cookies.set('name', 'value', { path: '' });     Cookies.remove('name'); //直接删除 失败     Cookies.remove('name', { path: '' }); // 删除成功!     IMPORTANT! when deleting a cookie, you must pass the exact same path and domain attributes that was used to set the cookie, unless you're relying on the default attributes.     Note: Removing unexisting cookie does not raise any exception nor return any value

  

摘自:https://www.cnblogs.com/xiangsj/p/9030648.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-15
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2021-11-29
  • 2021-07-08
  • 2022-01-31
  • 2021-06-14
相关资源
相似解决方案