<template>
<radio-group>
<view v-for="(item, index) in items" :key="index">
<radio :value="item.id" :checked="item.id==radioValue" @click="radioCheck(index)" class="round"></radio>
<label> 同意此协议</label>
</view>
</radio-group>
</template>
<script>
export default {
data( ) {
return {
radioValue: '',
items: [{
id: '1'
}]
}
},
methods: {
radioCheck (index) { // index 为当前项的索引
// 判断条件中的this.radioValue为点击之前的值
if(this.radioValue === this.items[index].id) {
// 选中之后再次点击
this.radioValue = null
} else {
// this.radioValue初始值为空 所以是未选中状态
this.radioValue = this.items[index].id
}
}
}
}
</script>