h5 新增特性 - WebStorage

WebStorage? ?

? ? ? ? ? ? ?Web項(xiàng)目存儲數(shù)據(jù)常用的方案:

? ? ? ? ? ? ?(1)服務(wù)器端存儲

??? ? ? ? ? ??????? 1)數(shù)據(jù)庫存儲,如商品、用戶等核心數(shù)據(jù)

?? ? ? ? ? ???????? 2)Session/內(nèi)存存儲,如用戶的登錄信息

?? ? ? ? ? ? (2)客戶端存儲

??? ? ? ? ? ??????? 3)Cookie存儲,如用戶偏好、訪問歷史,瀏覽器兼容性好但處理麻煩且容量限制

???? ? ? ? ? ?????? 4)H5 WebStorage存儲,如用戶偏好、訪問歷史等安全要求的數(shù)據(jù),老IE不兼容但易使用且容量大

? ? ? ? ? ? ?H5WebStorage存儲具體涉及到兩個(gè)對象:

?? ? ? ? ? ?? ? ? ? ? ? (1)window.sessionStorage:類數(shù)組對象,通過key=>value對存儲字符串?dāng)?shù)據(jù)——會話級存儲

????? ? ? ? ? ?? ? ? ? ? ????? 添加數(shù)據(jù):sessionStorage['key'] = 'value'

???? ? ? ? ? ?? ? ? ? ? ????? 修改數(shù)據(jù):sessionStorage['key'] = 'newValue'

???? ? ? ? ? ?? ? ? ? ? ?????? 刪除數(shù)據(jù):delete sessionStorage['key']

???? ? ? ? ? ?? ? ? ? ? ?????? 獲得數(shù)據(jù):var? v = sessionStorage['key']

?? ? ? ? ? ?? ? ? ? ? ? (2)window.localStorage:類數(shù)組對象,通過key=>value對存儲字符串?dāng)?shù)據(jù)——本地/跨會話級/永久存儲

???? ? ? ? ? ?? ? ? ? ? ?????? 添加數(shù)據(jù):localStorage['key'] = 'value'

????? ? ? ? ? ?? ? ? ? ? ????? 修改數(shù)據(jù):localStorage['key'] = 'newValue'

??????? ? ? ? ? ?? ? ? ? ? ??? 刪除數(shù)據(jù):delete localStorage['key']

????? ? ? ? ? ?? ? ? ? ? ????? 獲得數(shù)據(jù):var? v = localStorage['key']

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容