Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vuex-mapGetters等,但通过参数进行映射_Vue.js_Vuex - Fatal编程技术网

Vue.js Vuex-mapGetters等,但通过参数进行映射

Vue.js Vuex-mapGetters等,但通过参数进行映射,vue.js,vuex,Vue.js,Vuex,我正在尝试创建一个通用的过滤器组件,它从存储中获取数据 现在,我使用的是mapGetters,就像这样 ...mapGetters({ items: 'filters' }), 但我希望能够将它推广到我映射的getter props: { filterType: String }, computed: { ...mapGetters({ items: this.filterType }), } 这给了我以下的错误 Cannot read property 'no

我正在尝试创建一个通用的过滤器组件,它从存储中获取数据

现在,我使用的是
mapGetters
,就像这样

...mapGetters({
  items: 'filters'
}),
但我希望能够将它推广到我映射的getter

props: {
  filterType: String
},

computed: {
    ...mapGetters({
    items: this.filterType
  }),
}
这给了我以下的错误

Cannot read property 'nombre' of undefined
我知道我能做到:

computed: {
  items: function () {
      return this.$store.getters[this.filterType]
  }
}

但我只是想检查是否有办法将vue实例的属性与MapGetter一起使用,或者是否需要严格地对其中的Getter名称进行硬编码

也许这就是您要寻找的(或者至少最接近于使用
MapGetter
):

props: {
   filterType: String
},

computed: {
  ...mapState({
    items(state, getters) {
      return getters[this.filterType];
    }
  })
}