映射的Vuex函数“不是函数”,但仍会加载

时间:2019-01-09 20:30:52

标签: vue.js vue-component vuex

当我在安装的挂钩中调用映射的Vuex动作时,该动作有效,但在控制台中收到“ TypeError:xxx不是函数”错误。

这是该组件的整个脚本部分:

<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 个答案:

答案 0 :(得分:3)

您应将操作映射为methods而不是computed,请参见dispatch actions in components

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