{"id":204410,"date":"2020-11-13T08:53:59","date_gmt":"2020-11-13T00:53:59","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=204410"},"modified":"2020-11-02T10:13:26","modified_gmt":"2020-11-02T02:13:26","slug":"sessionstorage-localstorage","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/sessionstorage-localstorage.html","title":{"rendered":"\u539f\u6765\u5b83\u624d\u662f\u771f\u6b63\u7684\u7f13\u5b58\u673a\u5236"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u524d\u9762\u6211\u4eec\u5b66\u4e60\u4e86 cookie \u548c sessionStorage\uff0c\u4ed6\u4eec\u90fd\u5177\u6709\u5b58\u50a8\u529f\u80fd\uff0c\u4f46\u5404\u6709\u5404\u7684\u7528\u9014\u3002\u4eca\u5929\u6211\u4eec\u5b66\u4e60 LocalStorage\uff0c\u5b83\u624d\u662f\u771f\u6b63\u7684\u7f13\u5b58\u673a\u5236\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u901a\u5e38\u8bf4\u7684\u78c1\u76d8\u7f13\u5b58\uff0c\u4ed6\u53ef\u4ee5\u505a\u5230\u5728\u8fd9\u4e9b\u573a\u666f\u4e0b\u6570\u636e\u4e22\u5931\uff1a<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5237\u65b0\u9875\u9762; \u5b83\u4e0e sessionStorage \u4f7f\u7528\u4e00\u81f4\uff1a<\/p>\n \r\n\/\/ \u589e\u52a0\u4e00\u6761\u6570\u636e \r\nlocalStorage.setItem('name', '\u516c\u4f17\u53f7\u7d20\u71d5'); \r\nlocalStorage.setItem('logo', '\u524d\u7aef\u5c0f\u8bfe\uff0c \u5e2e\u52a9 10W \u4eba\u5165\u95e8\u5e76\u8fdb\u9636\u524d\u7aef'); \r\n \r\n\/\/ \u83b7\u53d6\u4e00\u6761\u6570\u636e\uff0ckey \u4e3a name \r\nconsole.log(localStorage.getItem('name')); \r\n\/\/ \u83b7\u53d6\u7b2c\u4e00\u6761\u6570\u636e\u7684 key \r\nconsole.log(localStorage.key(0)); \r\n\/\/ \u5220\u9664\u4e00\u6761\u6570\u636e\uff0ckey \u4e3a logo \r\nlocalStorage.removeItem('logo') \r\n\u4fdd\u5b58\u5728 localStorage \u7684\u6570\u636e\u4e0d\u4f1a\u81ea\u52a8\u6e05\u9664\uff0c\u9664\u975e\u901a\u8fc7\u4ee3\u7801\u6e05\u9664\uff0c\u6216\u8005\u6e05\u9664\u6d4f\u89c8\u5668\u7684\u7f13\u5b58\u3002\u4f46\u662f\u5b83\u53c8\u6709\u9650\u5236\uff0c\u6bd4\u5982\u6709\u4e9b\u6d4f\u89c8\u5668\u9650\u5236\u6700\u5927\u53ea\u80fd\u5b58\u50a8 5MB\u3002\u4f60\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u8c03\u8bd5\u6a21\u5f0f(Inspect)\u4e0b\u6253\u5f00\u7684 Application -> Local Storage \u4e2d\u67e5\u770b\u5b58\u50a8\u7684\u5185\u5bb9\uff0c\u4e5f\u53ef\u4ee5\u4fee\u6539\u3002\r\n<\/pre>\n |