el-table刷新后保持高亮并改变状态字段

文章描述了一个使用Vue.js框架开发的应用中,如何实现在表格中点击行进行高亮显示,以及在点击后更新右侧内容和状态的颜色。同时,详细介绍了数据初始化、事件监听、子组件通信以及接口调用更新状态的方法。
摘要由CSDN通过智能技术生成

一、需求:
1、点击左侧右边显示具体内容
2、点击右边确认 左侧依旧高亮并且改变启动状态颜色
3、点击刷新、重置、高级搜索等不高亮 右边也不显示具体内容

二、效果图:
在这里插入图片描述

三、具体实施

1、定义highlight-current-row 是否高亮行

<el-table ref="table" v-loading="crud.loading" :data="crud.data" highlight-current-row style="width: 100%;" @selection-change="crud.selectionChangeHandler" @current-change="handleCurrentChange">

2、初始化数据

data() {
  return {
    currentRow: null
  }
}

3、高亮显示方法 重点是setCurrentRow

// 高亮显示
highLightRow() {
   // currentRow 刷新前被点击行数据
   if (this.currentRow === null) return
   for (const item of this.crud.data) {
     if (item.subId === this.currentRow.subId) {
       this.$refs.table.setCurrentRow(item)
     }
   }
 }

4、将higLightRow放在自己所需要调用的地方

父组件

<projectMember ref="projectMember" :project-sub-list="crud.data" :proj-id="projId" :sub-no="subNo" :getdetail="getdetail" />
mounted() {
 this.highLightRow()
}
// 选中子项后,设置子项分配
handleCurrentChange(row) {
  this.highLightRow()
}

详情接口 以便左侧高亮改变状态字段

/* 取得项目状态*/
getdetail(id) {
  const params = {
    id: id
  }
  detail(params).then(data => {
    if (data) {
      this.crud.data.forEach(function(item) {
        if (item.subId === id) {
          item.updateStatus = data.updateStatus
          item.startStatus = data.startStatus
          item.linkStatus = data.linkStatus
        }
      })
    }
  })
},

子组件

props: {
  getdetail: {
    type: Function,
    default: null
  }
}

点击确定时调用

/* 确认提交*/
submitCrudForm() {
  this.$refs['form'].validate(valid => {
    if (valid) {
      if (!disUer) {
        add(this.form.projectMembers)
          .then(res => {
            this.$notify({
              title: '保存成功',
              type: 'success',
              duration: 2500
            })
            this.hanleProjectMember(this.subId)
            this.getdetail(this.subId)
            this.$refs['sure'].doClose()
          })
          .catch(err => {
            console.log(err.response.data.message)
          })
        return true
      } else {
        return false
      }
    }
  })
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值