2

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 ?

1
  • 1
    try this.$store.state.parameters.urls[pathFile] Commented Jan 17, 2020 at 11:27

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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;

Comments

1

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;

Comments

0

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];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.