vuex related

The core application is vuex store (warehouse), "store" is basically a container that contains most of the state of your application.

Different points vuex and simple global object:

1.vuex state memory is responsive to the time, Store state changes, the corresponding components will be efficient updating;

2. Do not directly modify the state of the store, and the only way to change it is submitted display of mutation, easy to track changes in each state.

 

state

vuex status can obtain the corresponding state, in order to facilitate a better calculation can be written to the calling component properties in the

Write:

import { mapState } from 'vuex'

computed: {

  ...mapState(['age'])

}

 

getter

Some status for deriving from the store, getters return value based on its dependencies are cached only when its value changes will not be dependent recalculated

Use a similar state:

this.$store.getters.isAdult

Write:

import { mapGetters } from 'vuex'

computed: {

  ...mapGetters(['isAdult'])

}

Guess you like

Origin www.cnblogs.com/allenzhang-920/p/10993331.html