el-table表格行取消高亮

表格行选中高亮 highlight-current-row

 <el-table
      ref="singleTableRef"
      v-loading="loading"
      :data="menuList"
      border
      row-key="menuId"
      :default-expand-all="isExpandAll"
      highlight-current-row // 表格行高亮
      @row-click="handleClick" // 行选择事件
      @current-change="handleCurrentChange" //当前行选择
    >

取消高亮:setCurrentRow()

proxy.$refs.singleTableRef.setCurrentRow(-1)

由于current-change事件只选中一次,因此需要同时使用row-click

let isFirst = ref(false)
let nowRow = ref(false) //此变量保证进行单选行切换时可以成功高亮
function handleCurrentChange(currentRow,oldCurrentRow) {
  if (oldCurrentRow!== undefined && currentRow.menuId !== oldCurrentRow?.menuId) {
    isFirst.value = true
    nowRow.value = true
  }
}
function handleClick(row, column, event) {
  if (!isFirst.value || nowRow.value) {
    isFirst.value = true
    nowRow.value = false
  }else{
    isFirst.value = false
    proxy.$refs.singleTableRef.setCurrentRow(-1)
  }
}

你可能感兴趣的:(javascript,vue.js,前端,elementui)