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