vuex中getters的两种调用方法

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'])
}

猜你喜欢

转载自blog.csdn.net/CSDN_go_die/article/details/121429448