I have saved some currency information in the state manager of my app and here is how I am accessing it:
For example, to retrieve the value of Euro against the dollar, I use the following code:
JSON.parse(this.$store.state.clientSide.currencyrates).rates.EURO
When a currency is selected through a click event, I extract the currency symbol and pass it to the code above to fetch the exchange rate.
let currency = e.currentTarget.getAttribute('currency');
let new_currency = currency.toUpperCase();
var state_fx = JSON.parse(this.$store.state.clientSide.currencyrates).rates.`${new_currency}`;
this.$store.commit('setCurrency', new_currency);
alert('state fx'+state_fx);
My expectation was for the alert()
to display the numerical exchange rate, however, I am instead getting a long string of
JSON.parse(this.$store.state.clientSide.currencyrates).rates.INR
when attempting to retrieve the rupee exchange rate.
Even trying the following:
var state_fx = "JSON.parse(this.$store.state.clientSide.currencyrates).rates."+new_currency;
results in the same outcome. How can I safely pass the currency symbol so that I receive the correct exchange rate?