【方式一】:通过设置customRow达到目的,点击时遍历所有行设置为正常颜色,把当前行设置为特殊颜色(高亮色)

HTML:

<a-table
ref="table"
size="small"
rowKey="id"
bordered
:columns="physicalSurveyColumns"
:data-source="physicalSurveyData"
:pagination="pagination"
:customRow="customRow"
>
</a-table>

JS -> methods:

// 自定义行
customRow(record) {
return {
on: {
click: (e) => {
const oldList = document.querySelectorAll('.checked-td-of-add-table')
if (oldList) {
for (let j = ; j < oldList.length; j++) {
oldList[j].classList.remove('checked-td-of-add-table')
}
} const children = e.target.parentNode.children
for (let i = ; i < children.length; i++) {
children[i].classList.add('checked-td-of-add-table')
}
}
}
}
}

CSS:

/deep/ .checked-td-of-add-table {
background-color: rgba(24, 144, 255, 0.5);
}

【方式二】:通过设置customRow达到目的,点击时记录ID,每一行就会自动加载style的样式,这里可以使用条件来达到加载不同样式的目的,比如设置行背景色:'background-color': record.id === this.physicalSurveyCurrRowId ? '#FFFF99' : 'white'

HTML:

<a-table
ref="table"
size="small"
rowKey="id"
bordered
:columns="physicalSurveyColumns"
:data-source="physicalSurveyData"
:pagination="pagination"
:customRow="customRow"
>
</a-table>

JS -> methods:

// 自定义行
customRow(record, index) {
return {
// 自定义属性,也就是官方文档中的props,可通过条件来控制样式
style: {
// 字体颜色
'color': record.id === this.physicalSurveyCurrRowId ? 'orange' : 'rgba(0, 0, 0, 0.65)',
// 行背景色
'background-color': record.id === this.physicalSurveyCurrRowId ? '#FFFF99' : 'white'
// // 字体类型
// 'font-family': 'Microsoft YaHei',
// // 下划线
// 'text-decoration': 'underline',
// // 字体样式-斜体
// 'font-style': 'italic',
// // 字体样式-斜体
// 'font-weight': 'bolder'
},
on: {
// 鼠标单击行
click: event => {
// 记录当前点击的行标识
this.physicalSurveyCurrRowId = record.id
}
}
}
}

【方式三】:与方式一类似,只是代码实现方式不同,通过设置customRow达到目的,点击时遍历所有行设置为正常颜色,把当前行设置为特殊颜色(高亮色)

HTML:

<a-table
ref="table"
size="small"
rowKey="id"
bordered
:columns="physicalSurveyColumns"
:data-source="physicalSurveyData"
:pagination="pagination"
:customRow="customRow"
>
</a-table>

JS -> methods:

// 自定义行
customRow(record, index) {
return {
on: {
// 鼠标单击行
click: event => {
event.currentTarget.parentNode.querySelectorAll('tr').forEach(item => {
item.style.background = 'white'
})
event.currentTarget.style.background = 'green'
}
}
}
}

【方式四】:通过设置customRow与rowClassName达到目的,点击时记录ID,rowClass就会根据是否是点击时的ID来加载指定的样式

HTML:

<a-table
ref="table"
size="small"
rowKey="id"
bordered
:columns="physicalSurveyColumns"
:data-source="physicalSurveyData"
:pagination="pagination"
:customRow="customRow"
:rowClassName="setRowClassName"
>
</a-table>

JS -> methods:

// 选中行
customRow(record, index) {
return {
on: {
click: () => {
this.physicalSurveyCurrRowId = record.id
}
}
}
},
setRowClassName(record) {
return record.id === this.physicalSurveyCurrRowId ? 'clickRowStyl' : ''
}

CSS:设置自定义行的悬浮样式

.ant-table-tbody {
.clickRowStyl:hover {
td {
background-color: #00b4ed;
}
}
}

都能达到目的,按需要选择。

antd-vue中table行高亮效果实现的更多相关文章

  1. JavaScript Table行定位效果

    作者:cloudgamer 时间: 2009-09-17 文档类型:原创 来自:蓝色理想 第 1 页 JavaScript Table行定位效果 [1] 第 2 页 JavaScript Table行 ...

  2. Vue中table表头合并的用法

    <div class="panel-container"> <div> <table class="table-head" wid ...

  3. Vue中table合并单元格用法

    <table> <tr> <th>地名</th> <th>结果</th> <th>人名</th> < ...

  4. vue中的路由高亮

  5. Vue中结合Flask与Node.JS的异步加载功能实现文章的分页效果

    你好!欢迎阅读我的博文,你可以跳转到我的个人博客网站,会有更好的排版效果和功能. 此外,本篇博文为本人Pushy原创,如需转载请注明出处:http://blog.pushy.site/posts/15 ...

  6. Vue中的动画效果

    Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.css ...

  7. bootstrap中table页面做省市区级联效果(级联库见前面级联编辑)(非select下拉框)

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. 使用CodeMirror在浏览器中实现编辑器的代码高亮效果

    使用CodeMirror在浏览器中实现编辑器的代码高亮效果 在网站后台管理中希望能够对网站的样式表css与js文件以及模板html进行管理,在编辑的时候只是以普通文本展示又太普通,显得好难看,于是便在 ...

  9. VUE中实现iview的图标效果时遇到的一个问题

    [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available ...

随机推荐

  1. 【NOI2017】游戏 题解(2-SAT+缩点)

    题目链接 题目大意:有四种场地$a,b,c,x$和三种赛车$A,B,C$,$a$不能跑$A$,$b$不能跑$B$,$c$不能跑$C$,$x$都可以跑.给定$n$个场地和$m$个四元组$(i,h_i,j ...

  2. FastAPI框架入门 基本使用, 模版渲染, form表单数据交互, 上传文件, 静态文件配置

    安装 pip install fastapi[all] pip install unicorn 基本使用(不能同时支持,get, post方法等要分开写) from fastapi import Fa ...

  3. 面试被问:如果系统 CPU 突然飙升且 GC 频繁,你该如何排查?

    出自:开源中国 原文:系统运行缓慢,CPU 100%,以及Full GC次数过多问题的排查思路 处理过线上问题的同学基本上都会遇到系统突然运行缓慢,CPU 100%,以及Full GC次数过多的问题. ...

  4. 006_go语言中的if else条件语句

    代码演示 package main import "fmt" func main() { if 7%2 == 0 { fmt.Println("7 is even&quo ...

  5. 初学者都在坑里!不要在Python中使用“+”来连接字符串

    很多初学者都像我一样,最开始使用Python时,会不自觉地使用“+”来连接字符串,就像在许多其他编程语言(比如Java)中那样,因为这样既直观又容易. 但我很快意识到成熟的开发人员似乎更喜欢使用.jo ...

  6. Spring Cloud 系列之 ZooKeeper 注册中心

    什么是注册中心 服务注册中心是服务实现服务化管理的核心组件,类似于目录服务的作用,主要用来存储服务信息,譬如提供者 url 串.路由信息等.服务注册中心是微服务架构中最基础的设施之一. 注册中心可以说 ...

  7. Java流程控制,for,switch,while.break,continue,return

    Java流程控制,for,switch,while.break,continue,return

  8. Spring Cloud 之 基础学习资料

    通过调研发现,官方及国内基础学习资料已经比较完善,故不再重复赘述,安静地做个搬运工. 如工作中遇到比较复杂或重要的点,再做详述. 官方 Spring 官方入门系列 服务注册与发现 Service Re ...

  9. JS学习第三天

    运算符: 赋值运算符 “=” ,将“=”右边的值赋值给左边 比较运算符 “>   <   >=  <=   ==   !=   ===”,  ==比较两边内容是否一致      ...

  10. 2020-07-20:你觉得redis有什么缺点,给你改进的话你会怎么改进?

    福哥答案2020-07-20: 1.由于 Redis 是内存数据库,短时间内大量增加数据,可能导致内存不够用.2.redis是单线程的,单台服务器无法充分利用多核服务器的CPU.3.遇到大量查询时容易 ...