what are the differences between mapState and mapGetters of vuex, and what are the scenarios used by both
what are the differences between mapState and mapGetters of vuex, and what are the scenarios used by both
there is an introduction on the official website
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 calculation properties so that you can press the key
// 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
}
})
}
mapGetters
helper function simply maps getter
in store
to the local evaluation attribute:
import { mapGetters } from 'vuex'
export default {
// ...
computed: {
// getter computed
...mapGetters([
'doneTodosCount',
'anotherGetter',
// ...
])
}
}
because I just learned vue, I don t quite understand what I read on the official website. there is such a requirement: button,, , planDetail(personid, plan, relation, productProperty) { let param = { personId: personid, ...
two pages: list and cart,list pages add shopping carts to vuex, use vue-router to jump to cart to modify the number of newly added items without updating the data, but the data in localStorage has been changed, you can modify the existing data, and refr...
data stored in 1.vuex will lose all data after refreshing the page (F5) 2. I don t want to lose it after refreshing the page. At the same time, I don t want to store it in session and local in window are there any corresponding data storage methods o...