state访问状态对象
1.计算属性computed
computed:{
count(){
return this.$store.state.count;
}
}
2.通过mapState的对象来赋值
import {mapState} from 'vuex';
computed:mapState({
count:state=>state.count
})
3.通过mapState的数组来赋值
computed:mapState(["count"])
Mutations修改状态
1.$store.commit('方法名',参数值)
2.
import { mapState,mapMutations } from 'vuex';
methods:mapMutations(['方法名','方法名']),
getters计算过滤操作
1.我们首先要在store.js里用const声明我们的getters属性。
2.在computed属性中加入mapGetters
const getters = {
count:function(state){
return state.count +=100;
}
}
....mapGetters(["count"])
actions异步修改状态
module模块组