- Inside store
state: {
count: 0
}
- Inside component
computed: {
count () {
return this.$store.state.count
}
}
- The mapState Helper
// in full builds helpers are exposed as Vuex.mapState
import { mapState } from 'vuex'
export default {
// ...
computed:
...mapState({
count: state => state.count,
countAlias: 'count',
// to access local state with `this`, a normal function must be used
countPlusLocalState (state) {
return state.count + this.localCount
}
})
}