A
A
Alex2019-03-19 17:56:12
Vue.js
Alex, 2019-03-19 17:56:12

How to call getter in another vuex module?

I am writing an application using vue, vuex and all sorts of stray. There are store/user.js and store/accesses.js modules. User has a getter that returns the id of the current user. In accesses there is a getter that returns a certain array of data. But I need to filter the data to return only those related to this user. I can't call the getter directly, because it's not the right module. And I have no idea what to do.

export default {
  state: {
    user: {
      isAuthenticated: false,
      uid: null
    }
  },
  mutations: { /* ... */ },
  getters: {
    isUserAuthenticated: state => state.user.isAuthenticated,
    userUid: state => state.user.uid
  }
}

state: {
    accesses: [
      {
        id: 'fsfwefsfadsfas',
        user: '6BlfZKVMUsWTd1W5KAHIZ3XLmmA2',
      },
      {
        id: 'fsfwefsfaeqwdsfas',
        user: '6BlfZKVMUsWTd1W5KAHIZ3XLmmA2',
      }
    ]
  },
  mutations: { /* ... */ },
  getters: {
    getAccesses: state => state.accesses
  },
  actions: { /* ... */ }
}

PS In principle, I can filter the data by user in the Accesses.vue component, but it seems to me that getting all the data (for all users) is not what is needed. Or am I running somewhere?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-19
@pilolin

We read the documentation more carefully. Pay special attention to the fourth parameter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question