getters和state用法相似,有点像vue中里面的data 和computed两个之间的关系
使用:
state: {
count:0,
},
getters:{
countAdd(state){
return state.count + 1
}
},
方法一:
this.$store.getters.xxx
xxx是getters里面的名称
方法二:
import { mapGetters } from 'vuex'
.....
computed:{
...mapGetters(['countAdd'])
}