DEV Community

Discussion on: How to query your API using Vuex in your Vue application

Collapse
jessachandler profile image
Jess Chandler

For anyone struggling to extend this to another variable, for example

export default new Vuex.Store({
  state: {
    users: [],
    bobs: []
  },
Enter fullscreen mode Exit fullscreen mode

You have to use the spread operator when you use them in the component

<script>
import {mapState} from "vuex";
export default {
  name: "hello-world",
  computed: {
    ...mapState(['users']),
    ...mapState(['bobs'])
  },
  created() {
    this.$store.dispatch('loadUsers');
    this.$store.dispatch('loadBobs')
  }
};
</script>
Enter fullscreen mode Exit fullscreen mode