How to understand the sentence that we can use the mapState helper function to help us generate calculation properties so that you can press the key a few times less?

in Vuex State document :

when a component needs to acquire multiple states, declaring these states as computational properties can be repetitive and redundant. To solve this problem, we can use the mapState helper function to help us generate computational 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
    }
  })
}

excuse me, We can use the mapState helper function to help us generate calculation properties so that you can press the key a few times less. , we can understand the first half of the sentence, but how do we understand the second half of that makes you press the key less ?

Mar.11,2021

helps you generate computational properties-> lets you type fewer lines of code--> lets you press fewer keys.

accept the humor.

The

mapSteta helper function helps us generate computational attributes, that is, the last computational attribute we use is generated, which reduces the amount of code


I don't quite understand what "generating calculation attribute" is.
is the original calculation content "only?" Do you use the traditional method of funciton?

myCount: function(){...},
myCount2: function(){...}

then can I use the arrow function in mapState?

< hr >

if you can read it again and again, is it possible to explain it this way?

In the

store component, there is a state attribute, and the "attribute" of the
state facet saves the data (that is, status).
to get those statuses: the easiest way is to return a state in the computed properties.

"mapState helper function"
means that if there are many attributes in state,
needs to recognize one of them in the component, which is a bit redundant.
use the mapState helper function to help us generate.
using his method, the mapping of state will be changed into a computational attribute, and the value of the variable will be returned.

Menu