[Vue] Dynamic component :is
We have a RadioGroup
component, when the prop vertical
is true
, we want all the Radio
wrap with div
, otherwise wrap with span
.
<template>
<component
v-for="option in options"
:key="option.value"
:is="vertical ? 'div' : 'span'"
:class="{
horizontal: !vertical
}"
>
<BaseRadio
:label="option.label"
:value="option.value"
:modelValue="modelValue"
:name="name"
@update:modelValue="$emit('update:modelValue', $event)"
/>
</component>
</template>
Parent component:
<h3>Are pets allowed?</h3>
<div>
<BaseRadioGroup
v-model="event.pets"
name="pets"
:options="petOptions"
vertical
/>
</div>