I have a parent component that's passing a prop (selectedOption) to a child component, and the child component takes the prop and renders an icon based on the prop. But every time I load the page, the child component throws an error because the prop has not been passed down in time, but it's fine after a second when everything is passed down. How can I avoid this?
Parent (Settings.vue):
<template>
<settings-menu
:selectedOption="selectedSettingsOption">
</settings-menu>
Child (SettingsMenu.vue):
<template>
<component
:is="`icon-${ selectedOption }`">
</component>
</template>
Just put a v-if to hide the component until the prop gets passed.
<template>
<component
v-if='selectedOption' :is="`icon-${ selectedOption }`">
</component>
</template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With