如何调用 vuex

<script>
import { mapState , mapMutations , mapActions , mapGetters } from 'vuex';
export default {
data(){
return{

}
},
computed:{
...mapState({
counts:(state) => state.count
}),
//mapState就等于下面这个
// counts(){
// return this.$store.state.count
// },
...mapGetters({
getternum:'doneTodos'
}),
//mapGetters就等于下面的这个
// getternum(){
// return this.$store.getters.doneTodos
// }

},
methods:{
...mapMutations({
addnum:'addNum'
}),
addnum1(){
this.addnum()
},
//mapMutations就等于下面的这个
// addnum1(){
// this.$store.commit('addNum')
// },

...mapActions({
actionnum:'actionNumAdd'
}),
actionnum6(){
this.actionnum()
},
//mapActions就等于下面的这个
// actionnum6(){
// this.$store.dispatch('actionNumAdd')
// }

}
}
</script>

原文地址:https://www.cnblogs.com/qlb-7/p/12751789.html