vuejs怎么实现v-for中的单选按钮
展开全部
<div id="subject-list-item">
<ol>
<div v-for="subject in subjects">
<li>
{{subject.question}}
<input type="radio" v-model="subject.answer_e" v-bind:value="subject.answer_a" >
<span>{{subject.answer_a}}</span>
<input type="radio" v-model="subject.answer_e" v-bind:value="subject.answer_b" >
<span>{{subject.answer_b}}</span>
<input type="radio" v-model="subject.answer_e" v-bind:value="subject.answer_c" >
<span>{{subject.answer_c}}</span>
<input type="radio" v-model="subject.answer_e" v-bind:value="subject.answer_d" >
<span>{{subject.answer_d}}</span>
</li>
</div>
</ol>
</div>
这里需要注意,v-model会变成value的值,所以不能单纯的从官网的例子上照抄。而是需要将v-model设置为一个动态的值。
<ol>
<div v-for="subject in subjects">
<li>
{{subject.question}}
<input type="radio" v-model="subject.answer_e" v-bind:value="subject.answer_a" >
<span>{{subject.answer_a}}</span>
<input type="radio" v-model="subject.answer_e" v-bind:value="subject.answer_b" >
<span>{{subject.answer_b}}</span>
<input type="radio" v-model="subject.answer_e" v-bind:value="subject.answer_c" >
<span>{{subject.answer_c}}</span>
<input type="radio" v-model="subject.answer_e" v-bind:value="subject.answer_d" >
<span>{{subject.answer_d}}</span>
</li>
</div>
</ol>
</div>
这里需要注意,v-model会变成value的值,所以不能单纯的从官网的例子上照抄。而是需要将v-model设置为一个动态的值。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询