HTML5 sessionStorage 使用
HTML5 sessionStorage 使用
实例:
function restore4Local() { if (window.localStorage) { user = user || {}; window.sessionId = localStorage.getItem("sessionId"); if (window.sessionId == null || window.sessionId == undefined) { return; } user.username = localStorage.getItem("user_username"); user.password = localStorage.getItem("user_password"); user.userId = localStorage.getItem("user_userId"); } } var restoreLoginDialog = function () { var $username = $('#uib_login input[name=username]'); var $password = $('#uib_login input[name=password]'); if (window.localStorage) { if (!$username.val()) { $username.val(localStorage.getItem("user_username")); $password.val(localStorage.getItem("user_password")); } } };
/*** * 清除localStorage */ function removeLocalStorage() { localStorage.removeItem("sessionId"); localStorage.removeItem("user_username"); localStorage.removeItem("user_password"); localStorage.removeItem("user_userId"); }
/*** * 使用sessionStorage保存数据 * @param key * @param objectVal : json对象 */ export function saveObj(key,objectVal) { window.sessionStorage.setItem(key, JSON.stringify(objectVal)); }; /*** * 使用sessionStorage恢复数据 * @param key */ export function getObj(key) { var val=window.sessionStorage.getItem(key); if(val){ return JSON.parse(val); }else{ return val; } }; export function removeItem(key) { window.sessionStorage.removeItem(key); }; export function removeStoreCache() { window.sessionStorage.removeItem(SESSIONSTORAGE_KEY_GZQ_APPLIST); window.sessionStorage.removeItem(SESSIONSTORAGE_KEY_GZQ_MOBILESTORECONFIG); };
参考:
https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
https://my.oschina.net/crazymus/blog/371757
相关推荐
coolhty 2020-05-09
zxznsjdsj 2019-12-18
HSdiana 2019-11-09
爱好HtmlCssJs 2019-11-07
javazhuanzai 2019-11-05
owhile 2015-02-19
WCschool官方 2015-10-23
htmlman0 2017-12-09
hanniuniu 2019-06-30
Noontec 2019-06-29
纯屌丝程序猿 2017-12-09
纯屌丝程序猿 2016-12-22
墨龙吟 2019-06-28
happyzhangyin 2016-03-19
zljiaa 2015-12-12
wxcmdn 2019-06-27
wxcmdn 2019-06-27