3👍
✅
Your initial state
state: {
data: "",
location: "New York"
}
sets data
to an empty string. This is most probably what’s producing the error due to
state.data.city.name
where city
is undefined on a String
.
Set your initial state data
to something that’s not going to cause errors before your async data has loaded
data: {
city: {
name: ''
}
}
Alternatively (and because the above appears to mess up your other logic), change your getter to be forgiving of empty data
getters: {
city (state) {
return state.data.city && state.data.city.name || ''
}
}
Source:stackexchange.com