How to access Vuex module getters and mutations?

后端 未结 6 1368
长发绾君心
长发绾君心 2021-01-30 13:04

I\'m trying to switch to using Vuex instead of my homegrown store object, and I must say I\'m not finding the docs as clear as elsewhere in the Vue.js world. Let\'s say I have a

6条回答
  •  野性不改
    2021-01-30 13:30

    The mapGetters helper simply maps store getters to local computed properties:

        import { mapGetters } from 'vuex'
    
        export default {
      // ...
      computed: {
        // mix the getters into computed with object spread operator
        ...mapGetters([
          'doneTodosCount',
          'anotherGetter',
          // ...
        ])
      }
    }
    If you want to map a getter to a different name, use an object:
    
        ...mapGetters({
      // map `this.doneCount` to `this.$store.getters.doneTodosCount`
      doneCount: 'doneTodosCount'
    })
    

提交回复
热议问题