使用
name=
单选按钮上的属性是HTML用于将其与其他收音机分组以获得相同输入的属性。您需要每个问题都具有唯一性。
这些问题已经有了
number
prop(我希望它是某种ID?如果不是,可以为每个属性添加一个ID属性)
我会将此传递给选择:
<Choice :choices="question.choices" :id="number"/>
然后在选项中渲染:
<template>
<div class="choice">
<div v-for="(choice, index) in choices" v-bind:key="index">
<label>
<input type="radio" :name="`answer-${id}`" />
<span class="label-text">{{ choice }}</span>
</label>
</div>
</div>
</template>
<script>
export default {
name: "Choice",
props: {
choices: Array,
id: Number
},
};
</script>
这将渲染
<input type="radio" name="answer-1" />