Vue el-table表格第一列序號(hào)與復(fù)選框hover切換方式
更新時(shí)間:2024年07月24日 10:37:08 作者:李澤舉
這篇文章主要介紹了Vue el-table表格第一列序號(hào)與復(fù)選框hover切換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
前言
項(xiàng)目中用vue element el-table
表格的第一列為鼠標(biāo)經(jīng)過(guò)時(shí)切換顯示序號(hào)與復(fù)選框
不影響當(dāng)前行的點(diǎn)擊事件 , 如跳轉(zhuǎn)詳情等操作
老規(guī)矩,先上效果圖
HTML
<el-table ref="table" :data="tableData" style="width: 100%" border stripe @cell-mouse-enter="cellEnter" @cell-mouse-leave="cellLeave" @selection-change="handleSelectionChange" @row-click="toDeatils" > <el-table-column type="selection" width="50" align="left"> <template #default="{ row, $index }"> <div v-if="columnCheckedId == row.id || checkedList[$index]" @click.stop > <el-checkbox v-model="checkedList[$index]" @change="cellCheckbox(row, $index)" ></el-checkbox> </div> <span v-else>{{ $index + 1 }}</span> </template> </el-table-column> <!-- 如有操作列 ↓--> </el-table>
JS
data() { return { columnCheckedId: '', tableData: [], //table數(shù)據(jù) multipleSelection: [], //table多選數(shù)據(jù) checkedList: [], //table多選選中數(shù)據(jù) } }, methods:{ handleSelectionChange(val) { this.multipleSelection = val if (this.multipleSelection.length == this.tableData.length) { this.multipleSelection.forEach((item, index) => { this.checkedList[index] = true }) } if (this.multipleSelection.length == 0) { this.checkedList = [] } this.$emit('selectList', this.multipleSelection) }, //鼠標(biāo)移入表格當(dāng)前行 cellEnter(row, column, cell, event) { this.columnCheckedId = row.id }, // 鼠標(biāo)移出表格當(dāng)前行 cellLeave(row, column, cell, event) { this.columnCheckedId = '' }, // 選中與否塞數(shù)據(jù) cellCheckbox(row, index) { if (this.checkedList[index]) { this.$refs.table.toggleRowSelection(row, true) } else { this.$refs.table.toggleRowSelection(row, false) } }, }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue前端項(xiàng)目自適應(yīng)布局的簡(jiǎn)單方法
最近項(xiàng)目開(kāi)發(fā)中遇到一個(gè)需求,需要實(shí)現(xiàn)寬度自動(dòng)適應(yīng),所以下面這篇文章主要給大家介紹了關(guān)于Vue前端項(xiàng)目自適應(yīng)布局的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06vue相關(guān)配置文件詳解及多環(huán)境配置詳細(xì)步驟
這篇文章主要介紹了vue相關(guān)配置文件詳解及多環(huán)境配置的教程,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05詳解element-ui表格中勾選checkbox,高亮當(dāng)前行
這篇文章主要介紹了詳解element-ui表格中勾選checkbox,高亮當(dāng)前行,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09