I have a component that takes an array of options objects, a name, and a v-model, and puts out a radio input with matching label for each of the options in that array of options.
options = [
{text: "Option 1", value="option-1" },
{text: "Option 2", value="option-2" },
]
"updateValue" : function(){
this.$emit('input', this.$refs.input.value);
}
<template v-for="option in options" >
<input
:value="option.value"
:id="name + option.value"
:name="name"
@input="updateValue()"
ref="input" />
<label :for="name + option.value">{{option.text}}</label>
</template>
I've found a similar pattern in this guide where a v-model is taken and then value emitted by watching the @input
event.
I cannot wrap my head around how to do this with a radio-type input. Setting :value="value"
as with say a text input would make all the radio values identical, which really doesn't work.