欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 艺术 > el-table下的复选框关联勾选

el-table下的复选框关联勾选

2025/3/31 6:45:01 来源:https://blog.csdn.net/weixin_44032619/article/details/146476110  浏览:    关键词:el-table下的复选框关联勾选

 效果展示:

  <el-table style="height: 500px;" :data="tableData" border empty-text="暂无数据" v-loading="loading":header-cell-style="{ 'text-align': 'center' }" :cell-style="{ 'text-align': 'center' }" show-overflow-tooltipref="multipleTable" @select="handleSelection" @select-all="handleCount"><el-table-column type="selection" width="40" fixed="left" />
</el-table>
// 多选
const checkId = ref([]);  
const multipleTable = ref()
// 手动勾选单选的情况
const handleSelection = (val) => {if (checkId.value.length > val.length) {// 取消选中let checkAll = checkId.value;checkId.value = val;checkAll.forEach((item) => {let v = val.find(i => i.qdfphm === item.gl_qdfphm);  //关联的条件if (v === undefined && item.gl_qdfphm != '') {multipleTable.value.toggleRowSelection(item, false);checkId.value = val.filter(v => item.id != v.id)}})} else {// 选中checkId.value = val;let v = val[val.length - 1];if (v.gl_qdfphm != '') {let vv = tableData.value.find(item => item.qdfphm == v.gl_qdfphm)  //关联的条件multipleTable.value.toggleRowSelection(vv, true);checkId.value.push(vv);}}if (chooseTab.value == 1) {badgeTotal.value.total_supply = checkId.value.length} else if (chooseTab.value == 2) {badgeTotal.value.total_delete = checkId.value.length}
}
// 手动勾选全选情况(计算总数)
const handleCount = (val) => {checkId.value = val;
}

总结:重点在toggleRowSelection()方法

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词