Mapped Vuex function "is not a function", but still loads

Viewed 9239

When I call a mapped Vuex action in my mounted hook, the action works, but I get "TypeError: xxx is not a function" error in the console.

Here's my whole script section for this component:

<script>
import SideNav from '@/components/SideNav.vue'
import ActionBar from '@/components/ActionBar.vue'
import Summaries from '@/components/Summaries.vue'
import { mapState, mapActions } from 'vuex'

export default {
  components: { SideNav, ActionBar, Summaries },
  computed: {
    ...mapState(['dataLoading']),
    ...mapActions(['init'])
  }, 
  mounted() {
    this.init();
  }
}
</script>

1 Answers

You should map Actions as methods instead of computed, see dispatch actions in components:

computed: {
  ...mapState(['dataLoading'])
},
methods: {
  ...mapActions(['init'])
},
mounted() {
  this.init();
}
Related