el-table 動態(tài)給每行增加class屬性的示例代碼
el-table 動態(tài)給每行增加class屬性
html代碼
row-class-name屬性,綁定方法
:row-class-name=“tableRowClassName”,
<el-table :data="tableData" border :row-class-name="tableRowClassName"> </el-table>
js代碼
tableRowClassName({row, rowIndex}),接受到兩個參數(shù)
① row,行數(shù)據(jù)
② rowIndex, 行索引
tableRowClassName({row, rowIndex}) { // 根據(jù)每行的數(shù)據(jù),判斷isError來增加class屬性 if (row.row.isError === true) { return 'warning-row' } else { return 'success-row' } // 根據(jù)行索引判斷,增加class屬性 if (rowIndex === 1) { return 'warning-row'; } else if (rowIndex === 3) { return 'success-row'; } return ''; }
css代碼
<style lang="scss" scoped> ::v-deep .el-table .warning-row { color: #f24835 !important; td{ color: #f24835 !important; } } ::v-deep .el-table .success-row{ color: #00c617 !important; td{ color: #00c617 !important; } } </style>
到此這篇關(guān)于el-table 動態(tài)給每行增加class屬性的文章就介紹到這了,更多相關(guān)el-table 增加class屬性內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
前端在el-dialog中嵌套多個el-dialog代碼實現(xiàn)
最近使用vue+elementUI做項目,使用過程中很多地方會用到dialog這個組件,有好幾個地方用到了dialog的嵌套,下面這篇文章主要給大家介紹了關(guān)于前端在el-dialog中嵌套多個el-dialog代碼實現(xiàn)的相關(guān)資料,需要的朋友可以參考下2024-01-01vue3+Element?Plus?v-model實現(xiàn)父子組件數(shù)據(jù)同步的案例代碼
這篇文章主要介紹了vue3+Element?Plus?v-model實現(xiàn)父子組件數(shù)據(jù)同步,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-01-01vue中el-table格式化el-table-column內(nèi)容的三種方法
本文主要介紹了vue中el-table格式化el-table-column內(nèi)容的三種方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08