Vue.js Vuex Maps是';他没有按预期工作
我有一个名称空间存储(namespaced:true),我正试图通过mapstations访问它。当我通过MapTranslations调用它时,它会导致“nota function”错误。当我直接通过这个$store调用它时,它工作正常。为什么MapTranslations版本不起作用?PSEDOO代码如下所示。FWIW我正在使用最新的Vue/Vuex版本Vue.js Vuex Maps是';他没有按预期工作,vue.js,vuex,Vue.js,Vuex,我有一个名称空间存储(namespaced:true),我正试图通过mapstations访问它。当我通过MapTranslations调用它时,它会导致“nota function”错误。当我直接通过这个$store调用它时,它工作正常。为什么MapTranslations版本不起作用?PSEDOO代码如下所示。FWIW我正在使用最新的Vue/Vuex版本 import { mapGetters, mapMutations } from 'vuex' computed: { ...map
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
},
}
突变/动作是
函数
,它位于方法
...mapMutations('someModule', ['bar']),
methods: {
...mapMutations('someModule', ['bar']),
executeBar() {
this.bar()
}
}
应该在方法中
...mapMutations('someModule', ['bar']),
methods: {
...mapMutations('someModule', ['bar']),
executeBar() {
this.bar()
}
}
有关
方法
和计算方法
之间的更多信息和比较,请参见此突变/动作是功能
,它们位于方法中
...mapMutations('someModule', ['bar']),
methods: {
...mapMutations('someModule', ['bar']),
executeBar() {
this.bar()
}
}
应该在方法中
...mapMutations('someModule', ['bar']),
methods: {
...mapMutations('someModule', ['bar']),
executeBar() {
this.bar()
}
}
有关
方法
和计算方法
之间的更多信息和比较,请参见此我尝试将其放入方法中,但得到了相同的错误。代码已更新above@ekjcfn3902039您需要调用MapTranslations
进入方法
。所以方法:{…mapTranslations('someModule',['bar'])}
.Yep@skirtle,就是这样。谢谢啊,谢谢@skirtle,我没有在方法中添加行。我尝试将它放入方法中,但我得到了相同的错误。代码已更新above@ekjcfn3902039您需要调用MapTranslations
进入方法
。所以方法:{…mapTranslations('someModule',['bar'])}
.Yep@skirtle,就是这样。谢谢啊,谢谢@shirtle,我错过了在方法中添加行。