【方式一】:通过设置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. pandas_读取Excel并筛选特定数据

    # C:\Users\lenovo\Desktop\总结\Python # 读取 Excel 文件并进行筛选 import pandas as pd # 设置列对齐 pd.set_option(&qu ...

  2. PHP acos() 函数

    实例 返回不同数的反余弦: <?phpecho(acos(0.64) . "<br>");echo(acos(-0.4) . "<br>&q ...

  3. 6.10 省选模拟赛 小C的利是 高斯消元 矩阵行列式

    LINK:小C的利是 想起来把这道题的题解写了 .一个常识:利是在广东那边叫做红包. 关于行列式的题目 不过我不太会23333..口胡还是可以的. 容易想到10分的状压.不过没什么意思. 仔细观察要求 ...

  4. idea修改module name后重启失效

    技术交流群 : 816227112 idea每次修改module name后重启,module还是会在后面加上原来的name. 这时修改: .idea下的modules.xml 内的module名即可 ...

  5. scala---lazy

    scala中用lazy定义的变量叫做惰性变量,会实现延迟加载.惰性变量只能是不可变的变量.并且只有在调用惰性变量的时候才会被初始化. class Test1 { } object Test1 { de ...

  6. Spring 基于注解的 IOC 配置

    创建 spring 的 的 xml 配置 文件 <context:component-scan base-package="com.itheim"/> 指定创建容器时要 ...

  7. C语言输出颜色

    命令后界面输出颜色 嵌入式终端界面输出日志时,为了区分输出的有用信息.错误信息,可以给不同级别的输出加上不同的颜色,以方便查看. 下面是颜色的定义: //颜色宏定义 #define NONE &quo ...

  8. 039_go语言中的排序

    代码演示: package main import "fmt" import "sort" func main() { strs := []string{&qu ...

  9. Python使用Tornado+Redis维护ADSL拨号服务器代理池

    们尝试维护过一个免费的代理池,但是代理池效果用过就知道了,毕竟里面有大量免费代理,虽然这些代理是可用的,但是既然我们能刷到这个免费代理,别人也能呀,所以就导致这个代理同时被很多人使用来抓取网站,所以当 ...

  10. e分钟带你利用Python制作词云图

    随着大数据时代的来临,数据分析与可视化,显得越来越重要,今天给小伙伴们带来一种最常见的数据可视化图形-词云图的制作方法. 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法 ...