html session,local,cookie存储

2021-05-29 17:04

阅读:399

标签:storage   获取   set   字符   客户   大小   val   临时   value   


npm install cookie_js --save

储存

cookie.set(‘key‘, ‘value‘);

cookie.set(key1: ‘value1‘; key2: ‘value2‘);

获取

cookie.get(‘key‘);

cookie.get(‘key1‘, ‘key2‘);

清除

cookie.remove(‘key‘);

cookie.remove(‘key1‘, ‘key2‘);

cookie.remove([ ‘key1‘, ‘key2‘ ]);

HTML5本地存储

存储大小:5M,存储于客户端,而且只能存储字符串类型


sessionStorage(临时性,关闭浏览器即清除

存储

window.sessionStorage.setItem("key", "value");

获取

window.sessionStorage.getItem("key");

删除

window.sessionStorage.removeItem("key");

清空

sessionStorage.clear();

localStorage(长期性,手动删除


将sessionStorage换位localStorage即可

html session,local,cookie存储

标签:storage   获取   set   字符   客户   大小   val   临时   value   

原文地址:https://www.cnblogs.com/rt8090/p/14707781.html


评论


亲,登录后才可以留言!