From 7cbeff59258a351ee6b707829a12eb846ed841eb Mon Sep 17 00:00:00 2001 From: roger_home_pc Date: Sun, 24 Sep 2023 22:14:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20mapState=20mapGetters=20ma?= =?UTF-8?q?pMutations=20mapActions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/ModuleB.js | 2 +- src/views/OptionsAPIView.vue | 157 +++++++++++++++++++++++------------ 2 files changed, 107 insertions(+), 52 deletions(-) diff --git a/src/store/modules/ModuleB.js b/src/store/modules/ModuleB.js index 0f1683a..78412a5 100644 --- a/src/store/modules/ModuleB.js +++ b/src/store/modules/ModuleB.js @@ -18,6 +18,6 @@ export const moduleB = { if (content.state.state_b > 50) { content.commit('mutation_b', {num: payload.num}) } - } + }, } } diff --git a/src/views/OptionsAPIView.vue b/src/views/OptionsAPIView.vue index dc72f0a..afef248 100644 --- a/src/views/OptionsAPIView.vue +++ b/src/views/OptionsAPIView.vue @@ -13,27 +13,44 @@

对mutations的操作

-

根-this.$store.commit('mutation', {num: 7}): - +

根-@click="mutation({num: 7})": +

-

A-this.$store.commit('mutation_a', {num: 8}): - +

A-@click="mutation_a({num: 8})": +

-

B-this.$store.commit('module_b/mutation_b', {num: 9}): - +

B-@click="mutation_b({num: 9})": +

对actions的操作

-

根-mutation: - +

根-@click="action({num: 7})": +

-

A-this.$store.dispatch('action_a', {num: 8}): - +

A-@click="action_a({num: 8})": +

-

B-this.$store.dispatch('module_b/action_b', {num: 9}): - +

B-@click="action_b({num: 9})": +

+ +

混合用法

+

state_b_getter_a: (state, getters) => state.module_b.state_b + getters.getter_a: {{ + state_b_getter_a + }}

+

state_a_getter_b: (state, getters) => state.module_a.state_a + getters["module_b/getter_b"]: {{ + state_a_getter_b + }}

+

state_b_getter_b: (state, getters) => state.state_b + getters.getter_b: {{ state_b_getter_b }} +

+

@click="mutation_a_count(100): + +

+

@click="action_b_count(200): + +

+