I have some currencies i have saved inside the state manager of my app and this is how i am calling it:
For instance, to get the value of Euro against dollar, i
JSON.parse(this.$store.state.clientSide.currencyrates).rates.EURO
I am getting the currency from a click event and once i acquire the currency symbol, i am passing it to the statement above to fetch me 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);
i was expecting alert() to show me the numeric value of the exchange rate but instead i get a long string of JSON.parse(this.$store.state.clientSide.currencyrates).rates.INR when i try getting the rupee exchange rate.
Doing this
var state_fx = "JSON.parse(this.$store.state.clientSide.currencyrates).rates."+new_currency;
produces same result. How can i pass the currency symbol safely so that i return the exchange rate?
You can use the bracket-notation:
JSON.parse(this.$store.state.clientSide.currencyrates).rates[new_currency]