需求:想要用多选框的样式,但是又想只能单选,所以做了这个
参考:https://www.cnblogs.com/MonaSong/p/11990024.html
<template>
<div>
<el-checkbox-group v-model="checkList" @change="changeCheck">
<el-checkbox v-for="(item, index) in list" :key="index" :label="index" :checked="item.checked">123</el-checkbox>
</el-checkbox-group>
</div>
</template>
export default {
data() {
return {
checkList: [],
list: [
{ checked: true },
{ checked: false }
]
}
},
methods: {
// 使用多选按钮实现单选功能
changeCheck () {
this.checkList.length > 1 && this.checkList.shift()
this.$nextTick(() => {
let val = this.checkList.length > 0 ? this.checkList[0] : ''
console.log(val)
})
}
}
}
网友评论