3👍
Cannot read property of undefined after fetching data?
In fact, it happens before the data is fetched, because the data is not present when the component gets rendered: points.returnPoints[0]
is undefined and trying to access the name
property results in an error.
Try this instead:
<div v-if="points.returnPoints.length && points.returnPoints[0].name !== 'Starting Point'"> ... </div>
The code above assumes that points.returnPoints
is an array. If it’s empty, the second condition won’t be checked and it won’t result in an error.
Source:stackexchange.com