1👍
✅
assuming that api.locations is an array of objects you’re not searching for the location name in addLocation. also are you sure that location_id is being set? if it is not you’re just dispatching a store event with a null locationName
something like this would work better for you
addLocation () {
let locationName = null
if (this.location_id) {
locationName = this.api.locations.find(item => item.id === this.location_id).name;
}
if(locationName) {
store.dispatch('location/storeLocation', {
location_id: this.location_id,
locations: locationName
})
}
}
more information on searching arrays from this answer
Source:stackexchange.com