1、效果图如下,功能:必修和选修不可同时勾选
2、代码如下文章来源地址https://www.toymoban.com/news/detail-665658.html
<template>
<el-table :data="addTableData" style="width: 100%">
<el-table-column label="必修" width="55px" align="center">
<template slot-scope="scope">
<el-checkbox v-model="checked1" :label="scope.row.id" @change="checkboxChange($event,scope.row.id,'checked2')"><span></span></el-checkbox>
</template>
</el-table-column>
<el-table-column label="选修" width="55px" align="center">
<template slot-scope="scope">
<el-checkbox v-model="checked2" :label="scope.row.id" @change="checkboxChange($event,scope.row.id,'checked1')"><span></span></el-checkbox>
</template>
</el-table-column>
<el-table-column prop="id" label="编号" width="60px" align="center"></el-table-column>
<el-table-column prop="name" label="名称" align="center"></el-table-column>
<el-table-column prop="name" label="学时" width="60px" align="center"></el-table-column>
</el-table>
</template>
export default {
data() {
return {
checked1:[],//必修已选
checked2:[],//选修已选
}
}
methods: {
checkboxChange(val,id,type) {
if(val === true) {
this[type] = this[type].filter(function(item) {
return item !== id; // 过滤出值不为2的元素
});
}
},
},
}
文章来源:https://www.toymoban.com/news/detail-665658.html
到了这里,关于实现el-table两列多选框且不可同时勾选的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!