{"id":1021,"date":"2023-03-12T09:31:43","date_gmt":"2023-03-12T01:31:43","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1021"},"modified":"2023-04-29T13:14:30","modified_gmt":"2023-04-29T05:14:30","slug":"mixed-use-of-vuex-state-monitoring-mapstate-and-ordinary-local-computing-attributes","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/mixed-use-of-vuex-state-monitoring-mapstate-and-ordinary-local-computing-attributes\/","title":{"rendered":"Vuex\u72b6\u6001\u76d1\u542cmapState\u4e0e\u666e\u901a\u7684\u5c40\u90e8\u8ba1\u7b97\u5c5e\u6027\u6df7\u5408\u4f7f\u7528"},"content":{"rendered":"<p>mapState\u5982\u679c\u548c\u666e\u901a\u7684\u5c40\u90e8\u8ba1\u7b97\u5c5e\u6027\u6df7\u5408\u4f7f\u7528\uff0c\u4f7f\u7528\u5bf9\u8c61\u5c55\u5f00\u8fd0\u7b97\u7b26(\u2026)<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-javascript\">data () {\n  return {\n    order: {\n      orderId: &#039;&#039;,\n      amount: 0.0\n    }\n  }\n},\ncomputed: {\n  amount () {\n    return this.order.amount\n  },\n  ...mapState({\n    order_create_watcher: state =&gt; state.order.order_create\n    order_confirm_watcher: state =&gt; state.order.order_confirm\n  })\n},\nwatch: {\n  amount: &#039;amountWatcher&#039;,\n  order_create_watcher: {\n    handler: &#039;orderCreateWatcher&#039;,\n    deep: true\n  },\n  order_confirm_watcher: {\n    handler: &#039;orderConfirmWatcher&#039;,\n    deep: true\n  }\n},\nmethods: {\n  amountWatcher (val, oldVal) {\n    ...\n  },\n  orderCreateWatcher (val, oldVal) {\n    ...\n  },\n  orderConfirmWatcher (val, oldVal) {\n    ...\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>mapState\u5982\u679c\u548c\u666e\u901a\u7684\u5c40\u90e8\u8ba1\u7b97\u5c5e\u6027\u6df7\u5408\u4f7f\u7528\uff0c\u4f7f\u7528\u5bf9\u8c61\u5c55\u5f00\u8fd0\u7b97\u7b26(\u2026) data () { return  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[279],"class_list":["post-1021","post","type-post","status-publish","format-standard","hentry","category-java","tag-vuex"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1021"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1021\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}