網上一直流傳的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>
cssfirefly
http://cssfirefly.cnblogs.com