单选框 点击勾选或取消赋值问题

<button @click="add"></button>
<tbody>
<tr v-for="item in data" >
<td >

{{item.name}}

</td>
<td >

{{item.price}}

</td>
<td >

<input name="" type="radio" >

</td>
</tr>
</tbody>
<script>
export default{

  data(){
      return{
          data:[]
      }
  },
methods:{
  add(){
      this.data.push({name:"apple",price:"8.0", isMainProduct:""},)
  }
}

}
</script>

求助,现在点击button 增加的数据的话怎么去绑定<input name="" type="radio" >,让它选中的时候isMainProduct的值为true,不选中时值为false? 请帮帮忙jiong

阅读 6.7k
1 个回答

你可以先在你写的html的input后面添加{{isMainProduct}},
input的本身添加v-model=isMainProduct,
在js 实例里面写先写一个属性isMainProduct:false,
这样 你选中input按钮 后面的值就会相应的改变了.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题