Vuex (two): getters and actions

【getters】

 Personal understanding: getters similar calculation properties vue object, in .vue file by  the method name (optional parameter) $ store.getters. Call within vuex in the store, the first parameter calculation method of internal getters State necessarily, the second parameter must be getters itself, pass the received parameters placed in the return of the function

1. getters Without parameter passing

<h2>{{$store.getters.powerCounter}}</h2>
getters: {
    powerCounter (state) {
      return state.counter * state.counter
    }
  }

2. getters case parameter passing

<h2>{{$store.getters.morethanAge(16)}}</h2>
getters: {
    morethanAge (state) {
      return function (age) {
        return state.students.filter(s => s.age > age)
      }
    }
  },

3. getters calls itself other calculation methods

<h2>{{$store.getters.useSelf}}</h2>
getters: {
    useSelf (state, getters) {
      return getters.powerCounter + 1234
    }
  },

 

【actions】

  Personal appreciated: Action Mutation similar to, but is used instead Mutation for asynchronous operations.

Guess you like

Origin www.cnblogs.com/xzweb/p/12431070.html