临时代码

main
roger_home_pc 1 year ago
parent 1f1fcf3b5d
commit 8eb4930f6c
  1. 45
      src/views/OptionsAPIView.vue

@ -1,17 +1,15 @@
<template>
<!-- 对state的操作 -->
<h3>对state的操作</h3>
<p><span><b>-this.$store.state.count: </b></span>{{ this.$store.state.count }}</p>
<p><span><b>A-this.$store.state.module_a.state_a: </b></span>{{ this.$store.state.module_a.state_a }}</p>
<p><span><b>B-this.$store.state.module_b.state_b: </b></span>{{ this.$store.state.module_b.state_b }}</p>
<p><span><b>-count: </b></span>{{ count }}</p>
<p><span><b>A-state_a: </b></span>{{ state_a }}</p>
<p><span><b>B-state_b: </b></span>{{ state_b }}</p>
<!-- 对getters的操作 -->
<h3>对getters的操作</h3>
<p><span><b>根this.$store.getters.getter(3): </b></span>{{ this.$store.getters.getter(3) }}</p>
<p><span><b>A-this.$store.getters.getter_a: </b></span>{{ this.$store.getters.getter_a }}</p>
<p><span><b>B-this.$store.getters['module_b/getter_b']: </b></span>{{
this.$store.getters['module_b/getter_b']
}}</p>
<p><span><b>-getter(3): </b></span>{{ getter(3) }}</p>
<p><span><b>A-getter_a: </b></span>{{ getter_a }}</p>
<p><span><b>B-getter_b: </b></span>{{ getter_b }}</p>
<!-- 对mutations的操作 -->
<h3>对mutations的操作</h3>
@ -27,11 +25,11 @@
<!-- 对actions的操作 -->
<h3>对actions的操作</h3>
<p><span><b>-this.$store.dispatch('action', {num: 7}): </b></span>
<p><span><b>-mutation: </b></span>
<button @click="root_action">如果store>50 点一下store+10</button>
</p>
<p><span><b>A-this.$store.dispatch('action_a', {num: 8}): </b></span>
<button @click="moduleA_action">如果state_a>50 点一下state_a+8</button>
<button @click="action_a">如果state_a>50 点一下state_a+8</button>
</p>
<p><span><b>B-this.$store.dispatch('module_b/action_b', {num: 9}): </b></span>
<button @click="moduleB_action">如果state_b>50 点一下state_b+9</button>
@ -39,10 +37,31 @@
</template>
<script>
import {mapState, mapGetters, mapMutations, mapActions} from "vuex";
export default {
name: "OptionsAPIView",
// computed mapStatemapGetters
computed: {
// state, statemap
...mapState(["count", "state_a"]),
// state
...mapState("module_b", ["state_b"]),
// Getters
...mapGetters(["getter", "getter_a"]),
// Getters
...mapGetters("module_b", ["getter_b"])
},
methods: {
// mutations
...mapMutations(["mutation", "mutation_a"]),
// mutations
...mapMutations("module_b", ["mutation_b"]),
// actions
...mapActions(["action", "action_a"]),
// actions
...mapActions("module_b", ["action_b"]),
// storemutation
root_mutation: function () {
this.$store.commit('mutation', {num: 7})
@ -53,7 +72,7 @@ export default {
},
// moduleBmutation
moduleB_mutation: function () {
this.$store.commit('module_b/mutation_b', {num: 9})
this.$store.commit('mutation_b', {num: 9})
},
// storeaction
root_action: function () {
@ -65,7 +84,7 @@ export default {
},
// moduleBaction
moduleB_action: function () {
this.$store.dispatch('module_b/action_b', {num: 9})
this.$store.dispatch('action_b', {num: 9})
}
}
}

Loading…
Cancel
Save