Reputation: 547
I'm trying to get a vuejs store variable like this :
const pathFile = `#pathFile_${this.devisDTO.code_produit}`;
const pathApp = this.$store.state.parameters.urls.${pathFile};
So in the second line ${pathFile}
is not interpreted in that way. Please could you help on how to write this ?
Upvotes: 2
Views: 823
Reputation: 743
you need to modify your code remove brackets from parameters.urls.${pathFile} to .urls.pathFile;
here is code..
const pathFile = `#pathFile_${this.devisDTO.code_produit}`;
const pathApp = this.$store.state.parameters.urls.pathFile;
Upvotes: 1
Reputation: 309
In JavaScript ${string_name}
is used inside template strings (1). If you want to access the value of a dictionary based on a string's content you should use the square brackets syntax. In your case
this.$store.state.url[path_file]
On a side note I suggest you to use store getters to access variables.
(1): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Upvotes: 4
Reputation: 18473
That's not valid javascript. I am guessing you meant to write the following:
const pathFile = `#pathFile_${this.devisDTO.code_produit}`;
const pathApp = this.$store.state.parameters.urls[pathFile];
Upvotes: 0
Reputation: 2321
pathFile is a normal variable. Remove the brackets from it.
const pathFile = `#pathFile_${this.devisDTO.code_produit}`;
const pathApp = this.$store.state.parameters.urls.pathFile;
Upvotes: 2