|
@@ -3,11 +3,19 @@
|
|
|
<h3>我叫:{{ name }}</h3>
|
|
|
<h3>今年:{{ $store.state.age }}岁</h3>
|
|
|
<h3>是个{{ sex }}孩</h3>
|
|
|
+ <h1>{{ $store.getters.newCount }}</h1>
|
|
|
+ <hr>
|
|
|
+ <h3>Getters:{{ newCount }}</h3>
|
|
|
+ <h2>State:{{ count }}</h2>
|
|
|
+ <button @click="addThing">增加</button>
|
|
|
+ <hr>
|
|
|
+ <button @click="reduceThing">减少</button>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { mapState } from 'vuex';
|
|
|
+// import {mapMutations} from 'vuex';
|
|
|
+import { mapState,mapGetters,mapActions } from 'vuex';
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -15,12 +23,28 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
computed:{
|
|
|
- ...mapState(["sex","name"])
|
|
|
+ ...mapState(["sex","name","count"]),
|
|
|
+ ...mapGetters(['newCount'])
|
|
|
},
|
|
|
created() {
|
|
|
- console.log(this.$store.state, "this");
|
|
|
+ console.log(this)
|
|
|
+ console.log(this.$store.getters.newCount, "this");
|
|
|
this.obj1 = this.$store.state;
|
|
|
},
|
|
|
+ methods:{
|
|
|
+ addThing() {
|
|
|
+ console.log(this.$store)
|
|
|
+ this.$store.commit('addCount',20)
|
|
|
+ },
|
|
|
+ // ...mapMutations(['reduceCount']),
|
|
|
+ ...mapActions(['asyncReduce']),
|
|
|
+ reduceThing() {
|
|
|
+ this.asyncReduce();
|
|
|
+ // this.reduceCount()
|
|
|
+ // this.$store.commit('reduceCount')
|
|
|
+ // this.$store.dispatch('asyncReduce')
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
</script>
|
|
|
|