mapMutations m
mapMutations
//触发store里面mutation的add方法,但是这样写不够简洁明了
<button @click="$store.commit('add',1)">+</button>mutation
methods: {
...mapMutations([
'add',
'reduce'
])
}
//这里因为有...mapmutations
//@click='reduce'等价于@click="$store.commit('reduce',1)"
<button @click="reduce">-</button>
mapGetters
export default {
computed: { ...mapGetters([ 'count' ]), }
}
等价于
export default {
computed: {count() {return this.$store.state.count }}
}
<template>
<p>{{$store.getters.count}}</p>
//等价于
<p>{{count}}</p>
<template>