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>

posted @ 2018-06-13 16:22  黄先森  阅读(867)  评论(0编辑  收藏  举报