highlight-current-row ////选中行高亮。二、在中添加如下方法。_el-table-column type="selection">
当前位置:   article > 正文

Vue el-table如何实现<el-table-column type=“selection“>单选_el-table-column type="selection

el-table-column type="selection

一、htmll 中添加

<el-table
  ref="multipleTable"
  :data="tableData"
  highlight-current-row     选中行高
  :row-key="getRowKey"
  @selection-change="selectItem"
  @row-click="onSelectOp"

>
  <el-table-column type="selection" width="55" align="center" />
  <el-table-column label="序号" type="index" align="center" />
  <el-table-column label="姓名" prop="name" align="center" />
  <el-table-column label="手机号码" prop="telephone" align="center" />
</el-table>
二、在<srcipt lang='ts' setup>中添加如下方法

function getRowKey(row:any) {

  return row.id

}

const multipleTable = ref();

const selectItem=(rows:any)=> {

  if (rows.length > 1) {

    const newRows = rows.filter((it:any, index:any) => {

      if (index == rows.length - 1) {

      multipleTable.value.toggleRowSelection(it, true);

        return true;

      } else {

       multipleTable.value.toggleRowSelection(it, false);

        return false;

      }

    });

    multipleSelection = newRows;

  } else {

    multipleSelection = rows;

  }

}

let multipleSelection = []

const onSelectOp=(row:any)=>{

 multipleTable.value.clearSelection();

 multipleTable.value.toggleRowSelection(row, true);

  multipleSelection = [];

  multipleSelection.push(row);

  console.log('onSelectOp >row',row);

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/114497?site
推荐阅读
相关标签
  

闽ICP备14008679号