Search code examples
javascriptvue.jsnuxt.jsvuex

Vuex - getters dynamically based on data property


I want to add a variable to my code, so it calls different functions when I need it but it doesn't work because of the string's quotes. What type should I use or how to strip those quotes from the string?

enter image description here


Solution

  • You could use brackets accessor :

    rawData(){
      return this.$store.getters['get'+this.dataName]
    }
    

    rawData should be a computed property and 'get'+this.dataName has to be in your getters like getTodos