当我在安装的挂钩中调用映射的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>
答案 0 :(得分:3)
您应将操作映射为methods
而不是computed
,请参见dispatch actions in components:
computed: {
...mapState(['dataLoading'])
},
methods: {
...mapActions(['init'])
},
mounted() {
this.init();
}