realize vuex modularization

This commit is contained in:
2022-06-09 16:10:30 +08:00
parent 3794916e17
commit d893b41c0b
6 changed files with 71 additions and 65 deletions

View File

@@ -1,11 +1,11 @@
<!--moguyun-->
<template>
<div>
<h3>当前最新的count值为{{$store.state.count}}</h3>
<h3>当前最新的count值为{{$store.state.countOptions.count}}</h3>
<button @click="addcount">+1</button>
<button @click="btnhandle">+1 Async</button>
<button @click="btnhandle1">+5 Async</button>
<h3>{{$store.getters.showNum}}</h3>
<h3>{{$store.getters['countOptions/showNum']}}</h3>
</div>
</template>
@@ -18,16 +18,17 @@ export default {
},
methods: {
addcount(){
this.$store.commit('add')
this.$store.commit('countOptions/add')
},
//异步让count自增1
btnhandle(){
//dispatch函数专门用来触发action
this.$store.dispatch('addAsync')
this.$store.dispatch('countOptions/addAsync')
},
btnhandle1(){
this.$store.dispatch('addNAsync',5)
this.$store.dispatch('countOptions/addNAsync',5)
}
}
},
}
</script>

View File

@@ -14,11 +14,11 @@ export default {
},
methods:{
divide(num){
this.$store.commit('divide',num)
this.$store.commit('countOptions/divide',num)
}
},
computed:{
...mapState(['count'])
...mapState('countOptions',['count'])
}
}
</script>

View File

@@ -16,12 +16,12 @@ export default {
return{ }
},
methods:{
...mapMutations(['subN','xc']),
...mapActions(['subNAsync']),
...mapMutations('countOptions',['subN','xc']),
...mapActions('countOptions',['subNAsync']),
},
computed:{
...mapState(['count']),
...mapGetters(['showNum','showNum1'])
...mapState('countOptions',['count']),
...mapGetters('countOptions',['showNum','showNum1'])
}
}
</script>