javascript - vue 元素加樣式該怎么做
問題描述
主要問題是: 之前記得能$index傳遞一個(gè)index然后就好辦了, 怎么知道當(dāng)前tr渲染是的是第幾行數(shù)據(jù), 如何用computed做
我想改變文字顏色
我的代碼:
問題解答
回答1:寫好樣式,然后動(dòng)態(tài)綁定 :class ='{green:true,red:false.....}'
回答2:你用的是element-ui框架吧,在el-table里有這么一個(gè)屬性row-class-name,是一個(gè)回調(diào)函數(shù),可以給table-cell加class。詳情你可以看一下官網(wǎng),在最下面。舉個(gè)栗子:(通過判斷一行數(shù)據(jù)中的值來顯示不同的背景顏色)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>
效果:
現(xiàn)在也可以啊,把v-for改成v-for='(item, index) in lists',inde就是索引了
相關(guān)文章:
1. 點(diǎn)擊頁面就自動(dòng)輸入到mysql.求解2. java - IDEA從SVN檢出項(xiàng)目 并在tomcat上運(yùn)行 求詳細(xì)流程3. node.js - 帶有node_modules目錄的項(xiàng)目,用phpstorm打開速度極慢,怎么解決?4. javascript - windos下第一次用Django無法正確創(chuàng)建工程目錄5. java - 多叉樹求值,程序高手,算法高手看過來6. node.js - nodejs使用formidable上傳文件問題7. java如何生成token?8. Laravel中文件上傳的問題9. 單擊登錄按鈕無反應(yīng)10. 靜態(tài)資源文件引入無效
