行样式(Row)
在iview的官方文档里有提供动态修改行样式的方法。
直接上代码演示。
html部分
<Table
:data="data1"
:columns="columns4"
:row-class-name="rowClassName"
></Table>
js部分
rowClassName (row, index) {
if (index === 1) {
return 'demo-table-info-row'
} else if (index === 3) {
return 'demo-table-error-row'
}
return ''
}
Css部分(注:如果使用了scoped的话,样式可能会添加不成功,可以尝试在外面写一个全局的样式表global.css,再在main.js中引入,或使用/deep/ <<<等深层选择器来覆盖iview的样式)
.ivu-table .demo-table-info-row td{
background-color: #434343!important;
}
.ivu-table .demo-table-error-row td{
background-color: #282828!important;
}
此处借用一位老哥(weixin_34189116)的demo图。
列样式(Col)
如果想单独修改某一列的样式,可以直接在columns的对象中添加className属性
html同上
<Table
:data="data1"
:columns="columns4"
:row-class-name="rowClassName"
></Table>
js部分
columns4: [
{
title: "时间",
key: "time",
className: "table_hl"
},
]
css部分(同样加入scoped有可能会导致样式添加不成功,方法同样是在外面新建一个全局样式表或使用深层选择器来覆盖iview的样式)
对表头也有样式效果
//对表头表单都有样式效果
.table_hl {
color: #1275df;
}
//只对表单内容有样式效果
.ivu-table-tbody .table_hl {
color: #1275df;
}
这里贴一张只对表单内容有样式效果的图。
再次说明,如果使用了scoped局部样式的,需要在外面新建全局样式表,或使用深层选择器/deep/ <<<等方法对iview的样式进行覆盖,不然很大可能无法实现样式修改。