Currently, I am retrieving a list of countries by making an API call in VueX
. The fetched data is then stored in a state using a mutation.
Essentially, the countries are saved in a variable known as this.$state.getters.countryList
, which can be accessed from a component. My goal is to check if a particular variable exists in this list.
To achieve this, I employ the following method:
this.$store.getters.countryList.indexOf('usa')
.
While I am certain that 'usa'
is included in the list, the result always returns as -1
.
In an attempt to debug and retrieve the actual value of this.$state.getters.countryList
, I utilize
console.log(this.$state.getters.countryList)
, but the console output shows [__ob__: Observer]
.
My objective is illustrated below:
mounted() {
if (this.$store.getters.countryList.indexOf('usa')) {
//Do something
}
}
How can I extract the real value of this.$state.getters.countryList
and use it efficiently with indexOf()
for conducting further checks or actions?