2019-09-02 13:47:34 4801瀏覽
今天千鋒扣丁學(xué)堂HTML5培訓(xùn)老師給大家分享一篇關(guān)于詳解element-ui表格中勾選checkbox,高亮當(dāng)前行的詳細(xì)介紹,首先大多數(shù)程序員遇到同樣的問題在做后臺(tái)管理系統(tǒng)的時(shí)候經(jīng)常需要操作表格,這里我們要實(shí)現(xiàn)的一個(gè)功能就是,勾選復(fù)選框,高亮顯示當(dāng)前行,也就是當(dāng)前行樣式改變。這是一個(gè)非常常見的使用場(chǎng)景,官網(wǎng)給我們提供了一個(gè)帶Checkbox的table表格,但是并沒有給出上述使用案例,解決辦法有很多,我簡(jiǎn)單總結(jié)下我自己的實(shí)現(xiàn)過程,希望能幫助到有同樣需求的小伙伴。
<el-table @selection-change="handleSelectionChange" >
tableData: [{ id:0, date: '2016-05-03', name: '王小虎', address: '上海市普陀區(qū)金沙江路 1518 弄' }
handleSelectionChange(val) { var arr = []; val.forEach((val, index) => { this.tableData.forEach((v, i) => { // id 是每一行的數(shù)據(jù)id if(val.id == v.id){ // console.log(i); arr.push(i) } }) }) this.multipleSelection = arr; }
<el-table @selection-change="handleSelectionChange" :row-class-name="rowStyle" >
this.multipleSelection.forEach((v)=>{ if(rowIndex === v){ return 'rowStyle' } })
rowStyle({row, rowIndex}){ let arr = this.multipleSelection; for(let i = 0; i < arr.length; i++){ if(rowIndex === arr[i]){ return 'rowStyle' } } }
</style> .rowStyle{ background-color:red!important; } </style>
.el-table{ width: 1163px; margin: 0 auto; .el-table__body{ tr:hover>td{ background-color:rgba(238,250,249,1)!important; } } }
【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】 【掃碼進(jìn)入HTML5前端開發(fā)VIP免費(fèi)公開課】
查看更多關(guān)于“HTML5開發(fā)技術(shù)資訊”的相關(guān)文章>>