MapState Auxiliary function in vuex

doesn"t understand how helper functions get multiple states in a document. Can you give a detailed and simple description of the
mapState helper function
when a component needs to obtain multiple states, declaring these states as computational properties is somewhat repetitive and redundant. To solve this problem, we can use the mapState helper function to help us generate the calculation properties so that you can press the key

a few times less.
//  Vuex.mapState
import { mapState } from "vuex"

export default {
  // ...
  computed: mapState({
    // 
    count: state => state.count,

    //  "count"  `state => state.count`
    countAlias: "count",

    //  `this` 
    countPlusLocalState (state) {
      return state.count + this.localCount
    }
  })
}
Jul.11,2021

if he doesn't have a namespace, he's just like this:

  

just means there are many ways to write it. Write it in computed, and the corresponding computed will automatically change if the store changes

.
Menu