{"id":893,"date":"2024-01-06T10:23:39","date_gmt":"2024-01-06T02:23:39","guid":{"rendered":"http:\/\/gjweb.top\/?p=893"},"modified":"2024-01-06T10:23:42","modified_gmt":"2024-01-06T02:23:42","slug":"harmonyos-4-0-%e5%85%a8%e5%b1%80%e7%8a%b6%e6%80%81%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=893","title":{"rendered":"HarmonyOS 4.0 \u5168\u5c40\u72b6\u6001\u7ba1\u7406"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u5f00\u53d1 Harmony \u5e94\u7528\u4e2d\u4f1a\u9047\u5230\u591a\u6a21\u5757\u6570\u636e\u5171\u4eab\u7684\u573a\u666f\uff0c\u5c1d\u8bd5\u5bfb\u627e\u7c7b\u4f3c\u4e8e vuex \u7684\u72b6\u6001\u7ba1\u7406\u4ed3\u5e93\uff0c\u5b98\u65b9\u63d0\u4f9b\u4e86 <strong>@StorageLink\u88c5\u9970\u5668<\/strong> \u7528\u4e8e\u505a\u5e94\u7528\u5185\u7684\u72b6\u6001\u540c\u6b65\uff0c\u5e76\u63d0\u4f9b\u53cc\u5411\u6570\u636e\u7ed1\u5b9a\u548c\u6570\u636e\u6301\u4e45\u5316\u7684\u529f\u80fd<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53cc\u5411\u540c\u6b65\u6570\u636e\u793a\u4f8b<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>@Entry\n@Component\nstruct EntryComponent {\n  @StorageLink('key1') link1: string = 'hello'\n  build() {\n    Column({ space: 20 }) {\n      Text(this.link1).fontSize(30)\n        .onClick(() =&gt; {\n          this.link1 = '\u4f60\u597d'\n        })\n    }\n  }\n}\n\n@Entry\n@Component\nstruct Entry2Component {\n  @StorageLink('key1') link1: string = ''\n  build() {\n    text(this.link1)\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u4ee3\u7801\u5f53 EntryComponent \u9875\u9762\u7684 key1 \u53d1\u751f\u6570\u636e\u53d8\u5316\u65f6\uff0c Entry2Component \u9875\u9762\u4f1a\u81ea\u52a8\u66f4\u65b0 key1 \u7684\u5e76\u6e32\u67d3\u5230\u9875\u9762\u4e0a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u6301\u4e45\u5316<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A\u9875\u9762<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PersistentStorage.PersistProp(\"key1\", \"hello\") \n\n@Entry\n@Component\nstruct EntryComponent {\n  @StorageLink('key1') link1: string = 'hello'\n  build() {\n    Column({ space: 20 }) {\n      Text(this.link1).fontSize(50)\n        .onClick(() =&gt; {\n          this.link1 = '\u4f60\u597d\uff0c\u9e3f\u8499\uff01'\n        })\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">b\u9875\u9762<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Entry\n@Component\nstruct EntryComponent {\n  @StorageLink('key1') link1: string = ''\n  build() {\n    Column({ space: 20 }) {\n      Text(this.link1)\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4e0a\u4ee3\u7801\u5f53 A \u9875\u9762\u6570\u636e\u53d1\u751f\u53d8\u5316\u65f6\uff0c B \u9875\u9762\u4f1a\u66f4\u65b0\u6570\u636e\uff0c\u5e76\u5bf9\u8be5\u6570\u636e\u8fdb\u884c\u6301\u4e45\u5316\u5904\u7406\uff08\u9000\u51fa\u5e94\u7528\u540e\u72b6\u6001\u4e0d\u4f1a\u88ab\u91cd\u7f6e\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5f00\u53d1 Harmony \u5e94\u7528\u4e2d\u4f1a\u9047\u5230\u591a\u6a21\u5757\u6570\u636e\u5171\u4eab\u7684\u573a\u666f\uff0c\u5c1d\u8bd5\u5bfb\u627e\u7c7b\u4f3c\u4e8e vuex \u7684\u72b6\u6001\u7ba1\u7406\u4ed3\u5e93\uff0c\u5b98\u65b9\u63d0\u4f9b\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-893","post","type-post","status-publish","format-standard","hentry","category-harmonyos4-0"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=893"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/893\/revisions"}],"predecessor-version":[{"id":894,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/893\/revisions\/894"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}