Search code examples
vue.jsvuex

How to access a module from a store by having its name as a string?


I'm new in Vuejs and I have a problem.

I need to use a store but I only have its name in string. I know that I can access the method that I wrote (all() ) of the store by writing : storeName.all

but I only have this.storeName as a string and writing this.storeName.all doesn't work


Solution

  • The store is basically an abject. We can access object properties in these ways:

    this.$store.storeName;
    

    or if we know store name in string, we can access like this :

    this.$store["storeName"];