When assigning results from GET requests to my Vuex state properties, it's expected that they won't be available instantly. However, I have a getter like the following:
findChampion: (state) => (id) => {
let championId = id.toString();
let champion = Object.values(state.champions).find(value => value.key === championId);
return champion
}
When this getter is called from a component, it appears that at the initial call, the state.champions
property is still null
, resulting in numerous errors within the component.
This is how I invoke the getter from my component:
<img :src="'http://ddragon.leagueoflegends.com/cdn/' + $store.getters.version + '/img/champion/' + $store.getters.findChampion(this.match.mainParticipant.championId).image.full" alt="">
Is there a way to ensure that my component waits for the Vuex state to be not null before calling the getter?
The error message currently being displayed is
TypeError: Cannot convert undefined or null to object