pwindy  
在完成任务的同时,还需要不断“复盘”,不论你多么的忙,都需要留下时间思考,可以思考哪些地方做的好,哪些地方我们可以改进,应该如何改进,注重总结才是王道

1.state(computed,  ...mapState

用来保存数据的

var state= { a:1 }

 

2.mutations(methods,  ...mapMutations

操控state里面的数据

const mutations = {
    addAge(state) { state.a++ }
    reduceAge(state) { state.a-- }
}

 

3.actions(methods,  ...mapActions

调用mutations里的方法,异步操作,可以对mutations里面的方法进行操作

const actions = {
      addAgePro(obj) {
        console.log(obj)
      },
      reduceAgePro(obj) {
        console.log(obj)
      }
}

其中打印的obj的结构为

commit: function, dispatch: function, getters: {}, rootGetters: {}, rootState: {__ob__:Observer}, state: {__ob__:Observer}

 

4.getters(computed,  ...mapGetters

相当于computed的作用,用于state数据的过滤操作

const getters = {
    forlist(state) {
       return state.a += 1
    }
}

 

 

posted on 2021-11-12 11:49  pwindy  阅读(188)  评论(0编辑  收藏  举报