{"id":521,"date":"2019-09-25T16:52:25","date_gmt":"2019-09-25T08:52:25","guid":{"rendered":"https:\/\/wp.winter-weng.cc\/work\/?p=521"},"modified":"2019-09-25T16:52:25","modified_gmt":"2019-09-25T08:52:25","slug":"js-localstorage-%e4%b8%8a%e9%99%90%e8%88%87-catch-error","status":"publish","type":"post","link":"https:\/\/wp.winter-weng.cc\/work\/?p=521","title":{"rendered":"[JS] localStorage \u4e0a\u9650\u8207 Catch Error"},"content":{"rendered":"\n<p>localStorage \u597d\u7528\u4e14\u65b9\u4fbf\uff0c\u4f46\u5176\u5bb9\u91cf\u96d6\u5927\u4ecd\u6709\u5927\u5c0f\u7684\u9650\u5236\uff0c\u4e26\u4e14\u6703\u6839\u64da\u700f\u89bd\u5668\u3001\u4f7f\u7528\u8005\u8a2d\u5b9a\u7684\u4e0d\u540c\u800c\u6709\u5dee\u7570\u3002<\/p>\n\n\n<p>\u900f\u904e <a rel=\"noreferrer noopener\" aria-label=\"Test of localStorage limits\/quota (\u5728\u65b0\u5206\u9801\u4e2d\u958b\u555f)\" href=\"https:\/\/arty.name\/localstorage.html\" target=\"_blank\">Test of localStorage limits\/quota<\/a> \u6b64\u7db2\u7ad9\u6703\u6301\u7e8c\u5728\u672c\u5730\u585e\u8cc7\u6599\u76f4\u5230\u585e\u4e0d\u4e0b\u70ba\u6b62\uff0c\u900f\u904e\u6b64\u65b9\u5f0f\u53ef\u4ee5\u6e2c\u8a66\u6bcf\u500b\u700f\u89bd\u5668\u7684\u9810\u8a2d\u5bb9\u91cf\uff1a<\/p>\n\n\n<p>Chrome 77 &#8211; 5200k<br \/>Safari 12 &#8211; 2600k<br \/>Firefox 67 &#8211; 5200k<\/p>\n\n\n<p>\u8003\u91cf\u5230\u8de8\u5e73\u53f0\uff0c\u8003\u91cf\u5230\u8de8\u5e73\u53f0\uff0c\u5b58\u5165\u7684\u8cc7\u6599\u76e1\u91cf\u8981\u5728 2.6M \u4ee5\u4e0b\u3002<\/p>\n\n\n<p>\u800c\u5982\u4f55\u77e5\u9053\u76ee\u524d\u7684 localStorage \u5132\u5b58\u4e86\u591a\u5c11\u8cc7\u6599\uff1f\u76ee\u524d\u9084\u6c92\u627e\u5230\u6bd4\u8f03\u6709\u6548\u7387\u7684\u65b9\u5f0f\u6216 API\uff0c\u53ea\u80fd\u571f\u6cd5\u7149\u92fc\u5730\u5c07\u8cc7\u6599\u4e00\u500b\u500b\u53d6\u51fa\u4f86\u52a0\u7e3d\u5f97\u5230\u5927\u7d04\u7684\u6578\u503c\u3002\u8acb\u53c3\u8003\uff1a<a rel=\"noreferrer noopener\" aria-label=\"How to find the size of localStorage (\u5728\u65b0\u5206\u9801\u4e2d\u958b\u555f)\" href=\"https:\/\/stackoverflow.com\/questions\/4391575\/how-to-find-the-size-of-localstorage\" target=\"_blank\">How to find the size of localStorage<\/a>\u3002<\/p>\n\n\n<p>\u53e6\u5916\u5728 setItem \u6642\uff0c\u5982\u679c\u5bb9\u91cf\u5df2\u7d93\u6eff\u4e86\uff0c\u53ef\u4ee5\u5229\u7528 <code>try ... catch ...<\/code> \u6355\u6349\u5230\u932f\u8aa4\uff0c\u4f46\u932f\u8aa4\u540d\u7a31\u4e5f\u56e0\u700f\u89bd\u5668\u800c\u7565\u6709\u4e0d\u540c\uff0c\u5982 Chrome \u70ba <code>QuotaExceededError<\/code>\u3001Safari \u70ba <code>QUOTA_EXCEEDED_ERR<\/code>\u3002\u8acb\u53c3\u8003 <a rel=\"noreferrer noopener\" aria-label=\"Dealing with localStorage errors (\u5728\u65b0\u5206\u9801\u4e2d\u958b\u555f)\" href=\"http:\/\/chrisberkhout.com\/blog\/localstorage-errors\/\" target=\"_blank\">Dealing with localStorage errors<\/a>\u3002<\/p>\n\n\n<p>\u5ef6\u4f38\u95b1\u8b80\uff1a<a href=\"https:\/\/www.html5rocks.com\/en\/tutorials\/offline\/quota-research\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Working with quota on mobile browsers (\u5728\u65b0\u5206\u9801\u4e2d\u958b\u555f)\">Working with quota on mobile browsers<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>localStorage \u597d\u7528\u4e14\u65b9\u4fbf\uff0c\u4f46\u5176\u5bb9\u91cf\u96d6\u5927&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[4],"tags":[],"class_list":["post-521","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/posts\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=521"}],"version-history":[{"count":0,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/posts\/521\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}