{"id":1149,"date":"2024-03-11T08:21:05","date_gmt":"2024-03-11T00:21:05","guid":{"rendered":"http:\/\/ericw.top\/?p=1149"},"modified":"2024-03-11T11:08:58","modified_gmt":"2024-03-11T03:08:58","slug":"%e6%a0%b8%e5%bf%83%e6%a6%82%e5%bf%b5-module","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=1149","title":{"rendered":"\u6838\u5fc3\u6982\u5ff5 &#8211; module"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\" id=\"toc-0\"><a><\/a>1.\u76ee\u6807<\/h3>\n\n\n\n<p>\u638c\u63e1\u6838\u5fc3\u6982\u5ff5 module \u6a21\u5757\u7684\u521b\u5efa<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-1\"><a><\/a>2.\u95ee\u9898<\/h3>\n\n\n\n<p>\u7531\u4e8e\u4f7f\u7528<strong>\u5355\u4e00\u72b6\u6001\u6811<\/strong>\uff0c\u5e94\u7528\u7684\u6240\u6709\u72b6\u6001<strong>\u4f1a\u96c6\u4e2d\u5230\u4e00\u4e2a\u6bd4\u8f83\u5927\u7684\u5bf9\u8c61<\/strong>\u3002\u5f53\u5e94\u7528\u53d8\u5f97\u975e\u5e38\u590d\u6742\u65f6\uff0cstore \u5bf9\u8c61\u5c31\u6709\u53ef\u80fd\u53d8\u5f97\u76f8\u5f53\u81c3\u80bf\u3002<\/p>\n\n\n\n<p>\u8fd9\u53e5\u8bdd\u7684\u610f\u601d\u662f\uff0c\u5982\u679c\u628a\u6240\u6709\u7684\u72b6\u6001\u90fd\u653e\u5728state\u4e2d\uff0c\u5f53\u9879\u76ee\u53d8\u5f97\u8d8a\u6765\u8d8a\u5927\u7684\u65f6\u5019\uff0cVuex\u4f1a\u53d8\u5f97\u8d8a\u6765\u8d8a\u96be\u4ee5\u7ef4\u62a4<\/p>\n\n\n\n<p>\u7531\u6b64\uff0c\u53c8\u6709\u4e86Vuex\u7684\u6a21\u5757\u5316<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"475\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-40-1024x475.png\" alt=\"\" class=\"wp-image-1152\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-40-1024x475.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-40-300x139.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-40-768x356.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-40-1536x713.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-40.png 1571w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-2\"><a><\/a><strong>3.\u6a21\u5757\u5b9a\u4e49<\/strong> - \u51c6\u5907 state<\/h3>\n\n\n\n<p>\u5b9a\u4e49\u4e24\u4e2a\u6a21\u5757 <strong>user<\/strong> \u548c <strong>setting<\/strong><\/p>\n\n\n\n<p>user\u4e2d\u7ba1\u7406\u7528\u6237\u7684\u4fe1\u606f\u72b6\u6001 userInfo <code class=\"prettyprint\" >modules\/user.<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const state = {\r\n  userInfo: {\r\n    name: &#039;zs&#039;,\r\n    age: 18\r\n  }\r\n}\r\n\r\nconst mutations = {}\r\n\r\nconst actions = {}\r\n\r\nconst getters = {}\r\n\r\nexport default {\r\n  state,\r\n  mutations,\r\n  actions,\r\n  getters\r\n}\r\n<\/code><\/pre>\n\n\n\n<p>setting\u4e2d\u7ba1\u7406\u9879\u76ee\u5e94\u7528\u7684 \u4e3b\u9898\u8272 theme\uff0c\u63cf\u8ff0 desc\uff0c <code class=\"prettyprint\" >modules\/setting.<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const state = {\r\n  theme: &#039;dark&#039;\r\n  desc: &#039;\u6d4b\u8bd5\u63cf\u8ff0&#039;\r\n}\r\n\r\nconst mutations = {}\r\n\r\nconst actions = {}\r\n\r\nconst getters = {}\r\n\r\nexport default {\r\n  state,\r\n  mutations,\r\n  actions,\r\n  getters\r\n}<\/code><\/pre>\n\n\n\n<p>\u5728<code class=\"prettyprint\" >store\/index.js<\/code>\u6587\u4ef6\u4e2d\u7684modules\u914d\u7f6e\u9879\u4e2d\uff0c\u6ce8\u518c\u8fd9\u4e24\u4e2a\u6a21\u5757<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >import user from &#039;.\/modules\/user&#039;\r\nimport setting from &#039;.\/modules\/setting&#039;\r\n\r\nconst store = new Vuex.Store({\r\n    modules:{\r\n        user,\r\n        setting\r\n    }\r\n})<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u6570\u636e, \u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u6a21\u5757\u540d\u8bbf\u95ee <code class=\"prettyprint\" >$store.state.\u6a21\u5757\u540d.xxx<\/code> =&gt; <code class=\"prettyprint\" >$store.state.setting.desc<\/code><\/p>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7 mapState \u6620\u5c04<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-3\"><a><\/a>\u83b7\u53d6\u6a21\u5757\u5185\u7684state\u6570\u636e<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-4\"><a><\/a>1.\u76ee\u6807\uff1a<\/h3>\n\n\n\n<p>\u638c\u63e1\u6a21\u5757\u4e2d state \u7684\u8bbf\u95ee\u8bed\u6cd5<\/p>\n\n\n\n<p>\u5c3d\u7ba1\u5df2\u7ecf\u5206\u6a21\u5757\u4e86\uff0c\u4f46\u5176\u5b9e\u5b50\u6a21\u5757\u7684\u72b6\u6001\uff0c\u8fd8\u662f\u4f1a\u6302\u5230\u6839\u7ea7\u522b\u7684 state \u4e2d\uff0c\u5c5e\u6027\u540d\u5c31\u662f\u6a21\u5757\u540d<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"991\" height=\"610\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-39.png\" alt=\"\" class=\"wp-image-1151\" style=\"width:465px;height:auto\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-39.png 991w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-39-300x185.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-39-768x473.png 768w\" sizes=\"(max-width: 991px) 100vw, 991px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-5\"><a><\/a>2.\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u6570\u636e<\/h3>\n\n\n\n<ol>\n<li>\u76f4\u63a5\u901a\u8fc7\u6a21\u5757\u540d\u8bbf\u95ee $store.state.\u6a21\u5757\u540d.xxx<\/li>\n\n\n\n<li>\u901a\u8fc7 mapState \u6620\u5c04\uff1a\n<ol>\n<li>\u9ed8\u8ba4\u6839\u7ea7\u522b\u7684\u6620\u5c04 mapState([ 'xxx' ])<\/li>\n\n\n\n<li>\u5b50\u6a21\u5757\u7684\u6620\u5c04 \uff1amapState('\u6a21\u5757\u540d', ['xxx']) - \u9700\u8981\u5f00\u542f\u547d\u540d\u7a7a\u95f4 <strong>namespaced:true<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const state = {\r\n  userInfo: {\r\n    name: &#039;zs&#039;,\r\n    age: 18\r\n  },\r\n  myMsg: &#039;\u6211\u7684\u6570\u636e&#039;\r\n}\r\n\r\nconst mutations = {\r\n  updateMsg (state, msg) {\r\n    state.myMsg = msg\r\n  }\r\n}\r\n\r\nconst actions = {}\r\n\r\nconst getters = {}\r\n\r\nexport default {\r\n  namespaced: true,\r\n  state,\r\n  mutations,\r\n  actions,\r\n  getters\r\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-6\"><a><\/a>3.\u4ee3\u7801\u793a\u4f8b<\/h3>\n\n\n\n<p>$store\u76f4\u63a5\u8bbf\u95ee<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >$store.state.user.userInfo.name<\/code><\/pre>\n\n\n\n<p>mapState\u8f85\u52a9\u51fd\u6570\u8bbf\u95ee<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >...mapState(&#039;user&#039;, &#091;&#039;userInfo&#039;]),\r\n...mapState(&#039;setting&#039;, &#091;&#039;theme&#039;, &#039;desc&#039;]),<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-7\"><a><\/a>\u83b7\u53d6\u6a21\u5757\u5185\u7684getters\u6570\u636e<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-8\"><a><\/a>1.\u76ee\u6807\uff1a<\/h3>\n\n\n\n<p>\u638c\u63e1\u6a21\u5757\u4e2d getters \u7684\u8bbf\u95ee\u8bed<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-9\"><a><\/a>2.\u8bed\u6cd5\uff1a<\/h3>\n\n\n\n<p>\u4f7f\u7528\u6a21\u5757\u4e2d getters \u4e2d\u7684\u6570\u636e\uff1a<\/p>\n\n\n\n<ol>\n<li>\u76f4\u63a5\u901a\u8fc7\u6a21\u5757\u540d\u8bbf\u95ee<code class=\"prettyprint\" >$store.getters[&#039;\u6a21\u5757\u540d\/xxx &#039;]<\/code><\/li>\n\n\n\n<li>\u901a\u8fc7 mapGetters \u6620\u5c04\n<ol>\n<li>\u9ed8\u8ba4\u6839\u7ea7\u522b\u7684\u6620\u5c04 <code class=\"prettyprint\" >mapGetters([ &#039;xxx&#039; ])<\/code><\/li>\n\n\n\n<li>\u5b50\u6a21\u5757\u7684\u6620\u5c04 <code class=\"prettyprint\" >mapGetters(&#039;\u6a21\u5757\u540d&#039;, [&#039;xxx&#039;])<\/code> - \u9700\u8981\u5f00\u542f\u547d\u540d\u7a7a\u95f4<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-10\"><a><\/a>3.\u4ee3\u7801\u6f14\u793a<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const getters = {\r\n  \/\/ \u5206\u6a21\u5757\u540e\uff0cstate\u6307\u4ee3\u5b50\u6a21\u5757\u7684state\r\n  UpperCaseName (state) {\r\n    return state.userInfo.name.toUpperCase()\r\n  }\r\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;!-- \u6d4b\u8bd5\u8bbf\u95ee\u6a21\u5757\u4e2d\u7684getters - \u539f\u751f --&gt;\r\n&lt;div&gt;{{ $store.getters&#091;&#039;user\/UpperCaseName&#039;] }}&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >computed:{\r\n  ...mapGetters(&#039;user&#039;, &#091;&#039;UpperCaseName&#039;])\r\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-11\"><a><\/a>\u83b7\u53d6\u6a21\u5757\u5185\u7684mutations\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-12\"><a><\/a>1.\u76ee\u6807\uff1a<\/h3>\n\n\n\n<p>\u638c\u63e1\u6a21\u5757\u4e2d mutation \u7684\u8c03\u7528\u8bed\u6cd5<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-13\"><a><\/a>2.\u6ce8\u610f\uff1a<\/h3>\n\n\n\n<p>\u9ed8\u8ba4\u6a21\u5757\u4e2d\u7684 mutation \u548c actions \u4f1a\u88ab\u6302\u8f7d\u5230\u5168\u5c40\uff0c<strong>\u9700\u8981\u5f00\u542f\u547d\u540d\u7a7a\u95f4<\/strong>\uff0c\u624d\u4f1a\u6302\u8f7d\u5230\u5b50\u6a21\u5757\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-14\"><a><\/a>3.\u8c03\u7528\u65b9\u5f0f\uff1a<\/h3>\n\n\n\n<ol>\n<li>\u76f4\u63a5\u901a\u8fc7 store \u8c03\u7528 $store.commit('\u6a21\u5757\u540d\/xxx ', \u989d\u5916\u53c2\u6570)<\/li>\n\n\n\n<li>\u901a\u8fc7 mapMutations \u6620\u5c04\n<ol>\n<li>\u9ed8\u8ba4\u6839\u7ea7\u522b\u7684\u6620\u5c04 mapMutations([ 'xxx' ])<\/li>\n\n\n\n<li>\u5b50\u6a21\u5757\u7684\u6620\u5c04 mapMutations('\u6a21\u5757\u540d', ['xxx']) - \u9700\u8981\u5f00\u542f\u547d\u540d\u7a7a\u95f4<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-15\"><a><\/a>4.\u4ee3\u7801\u5b9e\u73b0<\/h3>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const mutations = {\r\n  setUser (state, newUserInfo) {\r\n    state.userInfo = newUserInfo\r\n  }\r\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const mutations = {\r\n  setTheme (state, newTheme) {\r\n    state.theme = newTheme\r\n  }\r\n}<\/code><\/pre>\n\n\n\n<p>Son1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;button @click=&quot;updateUser&quot;&gt;\u66f4\u65b0\u4e2a\u4eba\u4fe1\u606f&lt;\/button&gt; \r\n&lt;button @click=&quot;updateTheme&quot;&gt;\u66f4\u65b0\u4e3b\u9898\u8272&lt;\/button&gt;\r\n\r\n\r\nexport default {\r\n  methods: {\r\n    updateUser () {\r\n      \/\/ $store.commit(&#039;\u6a21\u5757\u540d\/mutation\u540d&#039;, \u989d\u5916\u4f20\u53c2)\r\n      this.$store.commit(&#039;user\/setUser&#039;, {\r\n        name: &#039;xiaowang&#039;,\r\n        age: 25\r\n      })\r\n    }, \r\n    updateTheme () {\r\n      this.$store.commit(&#039;setting\/setTheme&#039;, &#039;pink&#039;)\r\n    }\r\n  }\r\n}<\/code><\/pre>\n\n\n\n<p>Son2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;button @click=&quot;setUser({ name: &#039;xiaoli&#039;, age: 80 })&quot;&gt;\u66f4\u65b0\u4e2a\u4eba\u4fe1\u606f&lt;\/button&gt;\r\n&lt;button @click=&quot;setTheme(&#039;skyblue&#039;)&quot;&gt;\u66f4\u65b0\u4e3b\u9898&lt;\/button&gt;\r\n\r\nmethods:{\r\n\/\/ \u5206\u6a21\u5757\u7684\u6620\u5c04\r\n...mapMutations(&#039;setting&#039;, &#091;&#039;setTheme&#039;]),\r\n...mapMutations(&#039;user&#039;, &#091;&#039;setUser&#039;]),\r\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-16\"><a><\/a>\u83b7\u53d6\u6a21\u5757\u5185\u7684actions\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-17\"><a><\/a>1.\u76ee\u6807\uff1a<\/h3>\n\n\n\n<p>\u638c\u63e1\u6a21\u5757\u4e2d action \u7684\u8c03\u7528\u8bed\u6cd5 (\u540c\u7406 - \u76f4\u63a5\u7c7b\u6bd4 mutation \u5373\u53ef)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-18\"><a><\/a>2.\u6ce8\u610f\uff1a<\/h3>\n\n\n\n<p>\u9ed8\u8ba4\u6a21\u5757\u4e2d\u7684 mutation \u548c actions \u4f1a\u88ab\u6302\u8f7d\u5230\u5168\u5c40\uff0c<strong>\u9700\u8981\u5f00\u542f\u547d\u540d\u7a7a\u95f4<\/strong>\uff0c\u624d\u4f1a\u6302\u8f7d\u5230\u5b50\u6a21\u5757\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-19\"><a><\/a>3.\u8c03\u7528\u8bed\u6cd5\uff1a<\/h3>\n\n\n\n<ol>\n<li>\u76f4\u63a5\u901a\u8fc7 store \u8c03\u7528 $store.dispatch('\u6a21\u5757\u540d\/xxx ', \u989d\u5916\u53c2\u6570)<\/li>\n\n\n\n<li>\u901a\u8fc7 mapActions \u6620\u5c04\n<ol>\n<li>\u9ed8\u8ba4\u6839\u7ea7\u522b\u7684\u6620\u5c04 mapActions([ 'xxx' ])<\/li>\n\n\n\n<li>\u5b50\u6a21\u5757\u7684\u6620\u5c04 mapActions('\u6a21\u5757\u540d', ['xxx']) - \u9700\u8981\u5f00\u542f\u547d\u540d\u7a7a\u95f4<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-20\"><a><\/a>4.\u4ee3\u7801\u5b9e\u73b0<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"280\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-41-1024x280.png\" alt=\"\" class=\"wp-image-1153\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-41-1024x280.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-41-300x82.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-41-768x210.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/03\/image-41.png 1370w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const actions = {\r\n  setUserSecond (context, newUserInfo) {\r\n    \/\/ \u5c06\u5f02\u6b65\u5728action\u4e2d\u8fdb\u884c\u5c01\u88c5\r\n    setTimeout(() =&gt; {\r\n      \/\/ \u8c03\u7528mutation   context\u4e0a\u4e0b\u6587\uff0c\u9ed8\u8ba4\u63d0\u4ea4\u7684\u5c31\u662f\u81ea\u5df1\u6a21\u5757\u7684action\u548cmutation\r\n      context.commit(&#039;setUser&#039;, newUserInfo)\r\n    }, 1000)\r\n  }\r\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;button @click=&quot;updateUser2&quot;&gt;\u4e00\u79d2\u540e\u66f4\u65b0\u4fe1\u606f&lt;\/button&gt;\r\n\r\nmethods:{\r\n    updateUser2 () {\r\n      \/\/ \u8c03\u7528action dispatch\r\n      this.$store.dispatch(&#039;user\/setUserSecond&#039;, {\r\n        name: &#039;xiaohong&#039;,\r\n        age: 28\r\n      })\r\n    },\r\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;button @click=&quot;setUserSecond({ name: &#039;xiaoli&#039;, age: 80 })&quot;&gt;\u4e00\u79d2\u540e\u66f4\u65b0\u4fe1\u606f&lt;\/button&gt;\r\n\r\nmethods:{\r\n  ...mapActions(&#039;user&#039;, &#091;&#039;setUserSecond&#039;])\r\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-21\"><a><\/a>Vuex\u6a21\u5757\u5316\u7684\u4f7f\u7528\u5c0f\u7ed3<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-22\"><a><\/a>1.\u76f4\u63a5\u4f7f\u7528<\/h3>\n\n\n\n<ol>\n<li><code class=\"prettyprint\" >state --&gt; $store.state.&lt;strong&gt;\u6a21\u5757\u540d&lt;\/strong&gt;.\u6570\u636e\u9879\u540d<\/code><\/li>\n\n\n\n<li><code class=\"prettyprint\" >getters --&gt; $store.getters[&#039;&lt;strong&gt;\u6a21\u5757\u540d&lt;\/strong&gt;\/\u5c5e\u6027\u540d&#039;]<\/code><\/li>\n\n\n\n<li><code class=\"prettyprint\" >mutations --&gt; $store.commit(&#039;&lt;strong&gt;\u6a21\u5757\u540d&lt;\/strong&gt;\/\u65b9\u6cd5\u540d&#039;, \u5176\u4ed6\u53c2\u6570)<\/code><\/li>\n\n\n\n<li><code class=\"prettyprint\" >actions --&gt; $store.dispatch(&#039;&lt;strong&gt;\u6a21\u5757\u540d&lt;\/strong&gt;\/\u65b9\u6cd5\u540d&#039;, \u5176\u4ed6\u53c2\u6570)<\/code><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-23\"><a><\/a>2.\u501f\u52a9\u8f85\u52a9\u65b9\u6cd5\u4f7f\u7528<\/h3>\n\n\n\n<p>1.import { mapXxxx, mapXxx } from 'vuex'<\/p>\n\n\n\n<p>computed\u3001methods: {<\/p>\n\n\n\n<p>\/\/ <strong>...mapState\u3001...mapGetters\u653ecomputed\u4e2d\uff1b<\/strong><\/p>\n\n\n\n<p>\/\/ <strong>...mapMutations\u3001...mapActions\u653emethods\u4e2d\uff1b<\/strong><\/p>\n\n\n\n<p>...mapXxxx(<strong>'\u6a21\u5757\u540d'<\/strong>, ['\u6570\u636e\u9879|\u65b9\u6cd5']),<\/p>\n\n\n\n<p>...mapXxxx(<strong>'\u6a21\u5757\u540d'<\/strong>, { \u65b0\u7684\u540d\u5b57: \u539f\u6765\u7684\u540d\u5b57 }),<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>2.\u7ec4\u4ef6\u4e2d\u76f4\u63a5\u4f7f\u7528 \u5c5e\u6027 <code class=\"prettyprint\" >{{ age }}<\/code> \u6216 \u65b9\u6cd5 <code class=\"prettyprint\" >@click=&quot;updateAge(2)&quot;<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u76ee\u6807 \u638c\u63e1\u6838\u5fc3\u6982\u5ff5 module \u6a21\u5757\u7684\u521b\u5efa 2.\u95ee\u9898 \u7531\u4e8e\u4f7f\u7528\u5355\u4e00\u72b6\u6001\u6811\uff0c\u5e94\u7528\u7684\u6240\u6709\u72b6\u6001\u4f1a\u96c6\u4e2d\u5230\u4e00\u4e2a\u6bd4\u8f83 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1152,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1149"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1149"}],"version-history":[{"count":2,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1149\/revisions"}],"predecessor-version":[{"id":1156,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1149\/revisions\/1156"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/1152"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1149"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}