客户需求:
- 单选radio选中后,再次点击需要可以取消选择功能
- 页面有很组多单选,要实现一个方法就能兼容
- 话不多说直接上代码
<span v-for="item in radioData" :key="item.value">
<input type="radio" @click="chcekRadio($event)" name="abutmentVal" v-model="myData.abutmentVal" :id="'Abutment'+ item.id" :value="item.id" />
<label :for="'Abutment'+ item.id" :value="item.id">{{ item.name }}</label>
</span>
-
//vue中radio单选框单击取消选中状态 chcekRadio ($event) { let _this = this; let objVal = _this.myData[$event.target.name]; window.setTimeout(() => { if (!!objVal && objVal == $event.target.value) { $event.target.checked = false _this.myData[$event.target.name] = '' } }, 0); },