网上一直流传的2种方法,一种复选框方案需求不接受,二种@click.native.prevent不能取消选中,
自己写了备注下
分析:
@click.native默认会触发2次,但是@click.native.prevent会阻止默认事件,会导致不能取消选中
所以我想忽略第一次事件,监听第二次事件做清空操作。
<template>
<div >
<el-radio v-model="radio" @click.native="clickitem('1')" label="1"></el-radio>
<el-radio v-model="radio" @click.native="clickitem('2')" label="2"></el-radio>
<h1>{{ radio }}</h1>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App',
radio: ''
}
},
methods: {
clickitem (val) {
console.log(val)
if (this.flag === true) {
this.radio === val ? this.radio = '' : this.radio = val
}
this.flag = true
setTimeout(() => {
this.flag = false
}, 300)
}
}
}
</script>
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有