How to call action inside action in Vuex
<p>I try to build a really small Vue App with a Rails API. So at the moment I work with Vue, Vue-Resource and Vuex. I'll fetch all users from the database und now i try to update one of them. So everythings works fine (patch User), but after running the updateUser action I want to run the fetchUsers action again to update the Vuex store. </p>

<p>But when the fetchUsers runs inside the updateUser promise I get the following error:</p>

<pre><code>undefined:1 Uncaught (in promise) TypeError: Cannot read property 'dispatch' of undefined
</code></pre>

<p>this is what my vuex/actions.js are looking:</p>

<pre><code>export const fetchUsers = function ({ dispatch, state }) {
  this.$http.get('http://localhost:3000/api/v1/users').then((response) =&gt; {
    dispatch('SET_USERS', response.data)
  }, (response) =&gt; {
    dispatch('SET_USERS', [])
    console.log(response)
  })
}

export const updateUser = function ({ dispatch, state }, user) {
  this.$http.patch('http://localhost:3000/api/v1/users/' + user.id, {user: user}).then((response) =&gt; {
    fetchUsers()
  }, (response) =&gt; {
    console.log(response)
  })
}
</code></pre>

<p>I now that the fetchUsers action somehow loses context(?) but I don't know how to deal with that! thanks for every help!</p>