主要問(wèn)題是: 之前記得能$index
傳遞一個(gè)index然後就好辦了, 怎麼知道當(dāng)前tr渲染是的是第幾行資料, 如何用computed
做
我想改變文字顏色
#我的程式碼:
光陰似箭催人老,日月如移越少年。
寫(xiě)好樣式,然後動(dòng)態(tài)綁定 :class ="{green:true,red:false.....}"
你用的是element-ui框架吧,在el-table
里有這么一個(gè)屬性row-class-name
,是一個(gè)回調(diào)函數(shù),可以給table-cell
加class。詳情你可以看官網(wǎng),在最下面。
舉個(gè)栗子:(透過(guò)判斷一行資料中的數(shù)值來(lái)顯示不同的背景顏色)
template
<el-table :data="roleMenuTable" border style="width: 100%" :row-class-name="tableRowClassName">
script
methods: {
// 已選擇渲染樣式
tableRowClassName (row, index) {
if (row.operation) {
return 'info-row'
} else {
return ''
}
}
}
style
<style>
.el-table .info-row{
background: #5CB85C;
}
</style>
效果: