【发布时间】:2019-12-25 15:52:21
【问题描述】:
我有一个命名空间存储(命名空间:true),我正在尝试通过 mapMutations 访问它。当我通过 mapMutations 调用它时,它会导致“不是函数”错误。当我通过 this.$store 直接调用它时,它工作正常。为什么 mapMutations 版本不起作用?伪代码如下所示。 FWIW 我正在使用最新的 Vue/Vuex 版本。
import { mapGetters, mapMutations } from 'vuex'
computed: {
...mapGetters('someModule', ['foo']),
...mapMutations('someModule', ['bar']),
}
mounted() {
this.$store.commit('someModule/bar'); // This works
this.bar(); // This gives me a "this.bar() is not a function" error
this.baz();
}
methods: {
baz() {
this.bar(); // This gives me a "this.bar() is not a function" error
},
}
【问题讨论】: