{"id":1361,"date":"2019-09-20T23:55:47","date_gmt":"2019-09-20T15:55:47","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=1361"},"modified":"2022-02-17T15:10:14","modified_gmt":"2022-02-17T07:10:14","slug":"2020ironman-svelte-writable-store","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2019\/09\/20\/2020ironman-svelte-writable-store\/","title":{"rendered":"\u7b2c\u5341\u4e00\u5c46\u9435\u4eba\u8cfd \u524d\u7aef\u5de5\u7a0b\u5e2b\u7684\u53e6\u4e00\u500b\u9078\u64c7 svelte DAY19- \u53ef\u4ee5\u5beb\u5165\u7684store"},"content":{"rendered":"<h1>writable store \u662f\u751a\u9ebc<\/h1>\n<p>writable store \u662f\u751a\u9ebc\u5462\uff0c\u5728\u4ecb\u7d39\u5b8c<a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/20\/2020ironman-svelte-readable-store\/\" title=\"readable store\">readable store<\/a>\u5f8c\uff0c\u4eca\u5929\u8981\u4f86\u8ddf\u5927\u5bb6\u5206\u4eab\u7684\u5c31\u662f writable store \u9019\u500b\u6771\u897f\uff0c\u76f8\u8f03\u65bc<a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/20\/2020ironman-svelte-readable-store\/\" title=\"readable store\">readable store<\/a>\u552f\u8b80\u7684store\uff0c writable store \u662f\u53ef\u4ee5\u8b93\u5143\u4ef6\u5beb\u5165\u3001\u66f4\u65b0\u7684 store\uff0c\u63a5\u4e0b\u4f86\u5728\u8aaa\u660e\u4e00\u4e0b\u751a\u9ebc\u6642\u5019\u7528\u8ddf\u5982\u4f55\u7528\u3002<!--more--><\/p>\n<h2>writable store \u751a\u9ebc\u6642\u5019\u7528<\/h2>\n<p>writable store \u7684\u4f7f\u7528\u6642\u6a5f\u5c31\u662f\u5728\u65bc\u6709\u8a31\u591a\u5143\u4ef6\u6703\u53bb\u66f4\u65b0\u90a3\u500b\u8cc7\u6599\uff0c\u7136\u5f8c\u6709\u53e6\u5916\u4e9b\u5143\u4ef6\u6703\u8b80\u53d6\u8a72\u8cc7\u6599\u6642\u4f7f\u7528\uff0c\u7c21\u55ae\u8209\u500b\u4f8b\u5b50\u5c31\u662f\u767b\u5165\u5f8c\u6703\u66f4\u65b0\u4f7f\u7528\u8005\u8cc7\u8a0a\uff0c\u767b\u51fa\u5f8c\u6703\u6e05\u9664\u4f7f\u7528\u8005\u8cc7\u8a0a\uff0c\u9084\u6709\u90e8\u5206\u5730\u5340\u6703\u63a5\u9732\u76ee\u524d\u767b\u5165\u7684\u4f7f\u7528\u8005\u8cc7\u6599\u3002<\/p>\n<h2>writable store \u600e\u9ebc\u7528<\/h2>\n<p>\u5982\u540c<a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/20\/2020ironman-svelte-readable-store\/\" title=\"readable store\">readable store<\/a>\uff0c writable store \u4e5f\u662f\u5ba3\u544a\u5728js\u4e4b\u4e2d\uff0c\u6240\u4ee5\u6211\u5011\u5148\u5beb\u4e00\u500b\u4f7f\u7528\u8005\u540d\u7a31\u7684 writable store \uff0c\u76f8\u95dc\u5167\u5bb9\u5982\u4e0b\u3002<\/p>\n<pre><code class=\"language-javascript\">\/\/ In stores.js\nimport {writable} from &#039;svelte\/store&#039;;\n\nexport const nameStore = writable(&#039;Login&#039;);<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\u6211\u5011\u5728App.svelte\u5167import\u9019\u500b<code><code>nameStore<\/code><\/code>\u9032\u4f86\u4e26\u4f7f\u7528\uff0c\u4f8b\u5b50\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre><code class=\"language-html\">&lt;script&gt;\nimport {nameStore} from &#039;.\/store.js&#039;;\n&lt;\/script&gt;\n\n&lt;div&gt;\nHello {$nameStore}\n&lt;\/div&gt;<\/code><\/pre>\n<p>\u7136\u5f8c\u6211\u5011\u518d\u52a0\u4e0a\u53e6\u5916\u4e00\u500b\u5143\u4ef6\u5c08\u9580\u66f4\u65b0<code><code>nameStore<\/code><\/code>\uff0c\u5167\u5bb9\u5982\u4e0b\u5217\u6240\u793a\u3002<\/p>\n<pre><code class=\"language-html\">&lt;script&gt;\nimport {nameStore} from &#039;.\/store.js&#039;;\n&lt;\/script&gt;\n\n&lt;input type=&quot;text&quot; bind:value={$nameStore} \/&gt;<\/code><\/pre>\n<p>\u5982\u6b64\u7576nameStore\u88ab\u66f4\u65b0\u6642\uff0cApp.svelte\u7684\u986f\u793a\u4e5f\u6703\u4e00\u540c\u66f4\u65b0\uff0c\u9019\u500b\u6771\u897f\u662f\u4e0d\u662f\u5f88\u65b9\u4fbf\u5462\uff0c\u6700\u5f8c\u8aaa\u660e\u4e00\u4e0bwritable\u9019\u65b9\u6cd5\u7b2c\u4e00\u500b\u53c3\u6578\u662f\u521d\u59cb\u503c\uff0c\u7b2c\u4e8c\u500b\u53c3\u6578\u662fcallback\u51fd\u5f0f\uff0c\u88e1\u9762\u8981\u5be6\u4f5c\u4e00\u500bset\u7684\u65b9\u6cd5\u8ddf\u56de\u50b3\u4e00\u500bupdate\u7684callback\u65b9\u6cd5\u3002<\/p>\n<h2>\u5c0f\u7d50<\/h2>\n<p>\u5728\u4eca\u5929\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b svelte store \u76f8\u95dc\u6587\u7ae0\u7684\u7b2c\u4e8c\u7bc7 writable store \u76f8\u95dc\u77e5\u8b58\uff0c\u5e0c\u671b\u5927\u5bb6\u80fd\u5920\u6709\u6240\u6536\u7a6b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>writable store \u662f\u751a\u9ebc writable store \u662f\u751a\u9ebc\u5462\uff0c\u5728\u4ecb\u7d39\u5b8creadable sto &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/20\/2020ironman-svelte-writable-store\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u7b2c\u5341\u4e00\u5c46\u9435\u4eba\u8cfd \u524d\u7aef\u5de5\u7a0b\u5e2b\u7684\u53e6\u4e00\u500b\u9078\u64c7 svelte DAY19- \u53ef\u4ee5\u5beb\u5165\u7684store\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[160,79],"class_list":["post-1361","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2019ironman","tag-svelte"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=1361"}],"version-history":[{"count":9,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1361\/revisions"}],"predecessor-version":[{"id":3004,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1361\/revisions\/3004"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=1361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=1361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=1361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}