本文介绍了将参数传递给 mapGetters的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的组件中使用 vuexmapGetters 助手.我得到了这个功能:

I use vuex and mapGetters helper in my component. I got this function:

getProductGroup(productIndex) {
  return this.$store.getters['products/findProductGroup'](productIndex)
}

是否可以以某种方式将其移动到 mapGetters?问题是我还向函数传递了一个参数,所以我找不到将它放在 mapGetters

Is it possible to move this somehow to mapGetters? The problem is that I also pass an argument to the function, so I couldn't find a way to put this in mapGetters

推荐答案

如果你的 getter 接受这样的参数:

If your getter takes in a parameter like this:

getters: {
  foo(state) {
    return (bar) => {
      return bar;
    }
  }
}

然后就可以直接映射getter了:

Then you can map the getter directly:

computed: {
  ...mapGetters(['foo'])
}

然后将参数传入this.foo:

mounted() {
  console.log(this.foo('hello')); // logs "hello"
}

这篇关于将参数传递给 mapGetters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 01:51