Getter 用于对 Store中的数据进行加工处理形成新的数据。
Getter 不会修改 Store 中的原数据,它只起到一个包装器的作用,将Store中的数据加工后输出出来。
const store = new Vuex.Store({
state:{
count:0
},
getters: {
showNum(state) {
return '当前最新的数量是:' + state.count
}
},
})
方法1:this.$store.getters.名称
方法2:mapGetters 映射为计算属性
import { mapGetters } from 'vuex' computed:{
...mapGetters(['showNum'])
}