[Vuejs]-Vue.js root variable

1👍

I would read the State Management part of the VueJS docs then checkout the Vuex docs. Once your data store get even mildly more complex your method of managing it with your sample code will become overwhelming.

-1👍

Your question doesn’t have anything to do with vue, but just plain javascript. To access object variables in javascript you have 2 ways, using the dot notation or bracket notation (I call it array notation):

const car = { wheels: 4, seats: 5, horsepower: 145 };

console.log(car.wheels);
console.log(car['wheels']); //same result

So

this.$root[this.coinName];

will give you the result you are looking for.

Leave a comment