【发布时间】:2019-08-01 05:39:03
【问题描述】:
表的行是使用v-for 循环在graphicState 中的对象数组上生成的。我正在尝试创建一列单选按钮。选中单选按钮时,应将graphicState[index].selected 设置为true。
这个post 很有趣,但是我如何使用将graphicState[index].selected 设置为true?
<form>
<div class="row">
<div class="col-md-12 " align="center">
<table class="table-striped" v-on:mouseleave="mouseleave()">
<thead>
<tr>
<th></th>
<th>Show</th>
<th>Select</th>
<th>Shape</th>
</tr>
</thead>
<tbody>
<tr v-for="(form, index) in graphicState" :key="index">
<td @click="removeDate(index)"><i class="far fa-trash-alt"></i></td>
<td>
<input type="checkbox" v-model="form.show">
</td>
<td>
<input type="radio" name="grp" id="grp" value="true" v-model="form.selected">
</td>
<td v-on:click="toggleShape(index)">
{{ form.shape }}
</td>
</tr>
</tbody>
</table>
<div v-for="(form, index) in graphicState " :key="index">
</div>
</div>
</div>
</form>
【问题讨论】:
-
提示:
v-model自动确定如何设置/获取值。您可以改用:value="form.selected"并使用事件(如@click或@change等)来控制更新的内容和时间。
标签: vue.js vuejs2 radio-button v-for