{"id":53438,"date":"2024-12-03T08:03:56","date_gmt":"2024-12-03T00:03:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53438\/"},"modified":"2024-12-03T08:03:56","modified_gmt":"2024-12-03T00:03:56","slug":"%e5%a6%82%e4%bd%95%e5%bd%bb%e5%ba%95%e6%b8%85%e9%99%a4-pinia-%e5%ad%98%e5%82%a8%e4%b8%ad%e7%89%b9%e5%ae%9a%e5%ae%9e%e4%be%8b%e7%9a%84%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53438\/","title":{"rendered":"\u5982\u4f55\u5f7b\u5e95\u6e05\u9664 Pinia \u5b58\u50a8\u4e2d\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5f7b\u5e95\u6e05\u9664 Pinia \u5b58\u50a8\u4e2d\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u5f7b\u5e95\u6e05\u9664 Pinia \u5b58\u50a8\u4e2d\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241130\/1732951489674abdc13e15a.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5f7b\u5e95\u6e05\u9664 Pinia \u5b58\u50a8\u4e2d\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5f7b\u5e95\u6e05\u9664 Pinia \u5b58\u50a8\u4e2d\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u6e05\u7406 pinia \u5b58\u50a8\u4e2d\u5c5e\u4e8e\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f<\/strong><\/p>\n<p>\u5728 pinia \u4e2d\uff0c\u5373\u4f7f\u4ece localstorage \u4e2d\u5220\u9664\u4e86\u6301\u4e45\u5316\u5b9e\u4f8b\u7684\u952e\uff0c\u4e5f\u65e0\u6cd5\u6e05\u7406\u5b9e\u9645\u5b9e\u4f8b\u4e2d\u7684\u6570\u636e\u3002\u4e3a\u4e86\u5f7b\u5e95\u6e05\u9664\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff0c\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<p>\u9996\u5148\uff0c\u8ba9\u6211\u4eec\u4fee\u6539\u73b0\u6709\u7684 clearopenxlibrarystore \u65b9\u6cd5\uff1a<\/p>\n<pre>actions: {\n  updateOpenXLibrary(OpenXLibrary: Object) {\n    this.OpenXLibrary = OpenXLibrary;\n    localStorage.setItem('yourLsKey', JSON.stringify(OpenXLibrary)); \/\/ \u540c\u6b65\u8bbe\u7f6e localstorage\n  },\n  clearOpenXLibraryStore() {\n    this.OpenXLibrary = {};\n    localStorage.removeItem('yourLsKey'); \/\/ \u540c\u6b65\u5220\u9664 localstorage\n  }\n}<\/pre>\n<p>\u901a\u8fc7\u66f4\u6539 updateopenxlibrary \u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u4fdd\u5728\u66f4\u65b0 pinia \u72b6\u6001\u7684\u540c\u65f6\u5c06\u6570\u636e\u540c\u6b65\u5230 localstorage\u3002\u76f8\u5e94\u5730\uff0cclearopenxlibrarystore \u65b9\u6cd5\u5c06\u6e05\u9664 pinia \u72b6\u6001\u5e76\u5220\u9664 localstorage \u4e2d\u7684\u5bf9\u5e94\u6761\u76ee\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u60a8\u5e94\u8be5\u5c06 yourlskey \u66ff\u6362\u4e3a\u6301\u4e45\u5316\u8be5 pinia \u5b9e\u4f8b\u65f6\u4f7f\u7528\u7684\u5b9e\u9645 localstorage \u952e\u540d\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u5f7b\u5e95\u6e05\u9664 Pinia \u5b58\u50a8\u4e2d\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u7f16\u7a0b\u5165\u95e8\u6307\u5357\uff1a\u5982\u4f55\u5b66\u4e60\u7535\u8111\u7f16\u7a0b\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5f7b\u5e95\u6e05\u9664 Pinia \u5b58\u50a8\u4e2d\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f \u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0\u300a\u5982\u4f55\u5f7b\u5e95\u6e05\u9664 Pinia \u5b58\u50a8\u4e2d\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f\u300b\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01 \u5982\u4f55\u6e05\u7406 pinia \u5b58\u50a8\u4e2d\u5c5e\u4e8e\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff1f \u5728 pinia \u4e2d\uff0c\u5373\u4f7f\u4ece localstorage \u4e2d\u5220\u9664\u4e86\u6301\u4e45\u5316\u5b9e\u4f8b\u7684\u952e\uff0c\u4e5f\u65e0\u6cd5\u6e05\u7406\u5b9e\u9645\u5b9e\u4f8b\u4e2d\u7684\u6570\u636e\u3002\u4e3a\u4e86\u5f7b\u5e95\u6e05\u9664\u7279\u5b9a\u5b9e\u4f8b\u7684\u6570\u636e\uff0c\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a \u9996\u5148\uff0c\u8ba9\u6211\u4eec\u4fee\u6539\u73b0\u6709\u7684 clearopenxlibrarystore \u65b9\u6cd5\uff1a actions: { updateOpenXLibrary(OpenXLibrary: Object) { this.OpenXLibrary = OpenXLibrary; localStorage.setItem(&#8216;yourLsKey&#8217;, JSON.stringify(OpenXLibrary)); \/\/ \u540c\u6b65\u8bbe\u7f6e localstorage }, clearOpenXLibraryStore() { this.OpenXLibrary = {}; localStorage.removeItem(&#8216;yourLsKey&#8217;); \/\/ \u540c\u6b65\u5220\u9664 localstorage } } \u901a\u8fc7\u66f4\u6539 updateopenxlibrary \u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u4fdd\u5728\u66f4\u65b0 pinia \u72b6\u6001\u7684\u540c\u65f6\u5c06\u6570\u636e\u540c\u6b65\u5230 localstorage\u3002\u76f8\u5e94\u5730\uff0cclearopenxlibrarystore \u65b9\u6cd5\u5c06\u6e05\u9664 pinia \u72b6\u6001\u5e76\u5220\u9664 localstorage \u4e2d\u7684\u5bf9\u5e94\u6761\u76ee\u3002 \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u60a8\u5e94\u8be5\u5c06 yourlskey [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-53438","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53438"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53438\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}