javascript - vue 元素加樣式該怎么做
問題描述
主要問題是: 之前記得能$index傳遞一個index然后就好辦了, 怎么知道當前tr渲染是的是第幾行數據, 如何用computed做
我想改變文字顏色
我的代碼:
問題解答
回答1:寫好樣式,然后動態綁定 :class ='{green:true,red:false.....}'
回答2:你用的是element-ui框架吧,在el-table里有這么一個屬性row-class-name,是一個回調函數,可以給table-cell加class。詳情你可以看一下官網,在最下面。舉個栗子:(通過判斷一行數據中的值來顯示不同的背景顏色)template
<el-table :data='roleMenuTable' border :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>
效果:
現在也可以啊,把v-for改成v-for='(item, index) in lists',inde就是索引了
相關文章:
