vue中操作cookie的插件


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM