1👍
✅
Since selectedPlan
may not be available(or has null
value) on the first render, you are facing that error. You have one of three ways to solve this issue:
- Add a loader and wait until
selectedPlan
is available (best way in my opinion from the UX perspective) - Add a null check before accessing values like:
{{ (selectedPlan || {}).periodTitle }}
Or much better, use a computed property:
computed: {
safeSelectedPlan: () => {
return this.selectedPlan || {}
}
}
and then use safeSelectedPlan
in your template.
- Use a library like
lodash
toget
the values for variables safely.
Here is the documentation link to lodash: https://lodash.com/docs/4.17.15
Source:stackexchange.com