A
A
Alexey Sklyarov2018-11-21 17:32:38
Vue.js
Alexey Sklyarov, 2018-11-21 17:32:38

What is the correct way to use component parameter as getter name (vuex)?

There is a component to which I pass type: In the component itself, I declare a computed property:<component :type=" 'string' "></compontent>

computed: {
      ...mapGetters('currency', {
        coordinates: this.type,
      })
    },

Thus, the coordinates property is undefined, but if I just write the name of the getter I need, then everything works. How can this problem be solved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-11-21
@0example

computed: {
  coordinates() {
    return this.$store.getters[`currency/${this.type}`];
  },
},

UPD.
Why such difficulties? Simple enough type="string".

N
nvdfxx, 2018-11-21
@nvdfxx

try setting this getter the old fashioned way this.$store.getters.currency({coordinates: this.type})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question