您现在的位置:首页 >> 前端 >> 内容

vuex study之getters计算过滤操作

时间:2018/1/2 11:03:16 点击:

  核心提示:首先store里面声明getters//声明getters,就是每次count改变时先加上100const getters = {count:function(state){return state....

首先store里面声明getters

//声明getters,就是每次count改变时先加上100
const getters = {
    count:function(state){
        return state.count +=100;
    }
}

//导出
export default new Vuex.Store({
    //导出状态常量
    state,
    //导出mutations
    mutations,
    //导出getters
    getters
})

然后修改Count.vue组件

computed:{
            //扩展mapState
            ...mapState(['count']),
            count(){
                return this.$store.getters.count;
            }
        }

简写:需另外引入mapGetters

import { mapState,mapMutations,mapGetters } from 'vuex'

computed:{
            //扩展mapState
            ...mapState(['count']),
            ...mapGetters(['count'])
        }

Tags:VU UE EX XS 
作者:网络 来源:z858466的博客