Vue el-table表格第一列序號與復(fù)選框hover切換方式
更新時間:2024年07月24日 10:37:08 作者:李澤舉
這篇文章主要介紹了Vue el-table表格第一列序號與復(fù)選框hover切換方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
前言
項目中用vue element el-table
表格的第一列為鼠標經(jīng)過時切換顯示序號與復(fù)選框
不影響當前行的點擊事件 , 如跳轉(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)
},
//鼠標移入表格當前行
cellEnter(row, column, cell, event) {
this.columnCheckedId = row.id
},
// 鼠標移出表格當前行
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é)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3中我的Watch為什么總監(jiān)聽不到數(shù)據(jù)詳解
這篇文章主要介紹了Vue3中Watch為什么總監(jiān)聽不到數(shù)據(jù)的相關(guān)資料,文中還分析了Vue3中的watch監(jiān)聽函數(shù)和直接監(jiān)聽對象的區(qū)別,通過代碼介紹的非常詳細,需要的朋友可以參考下2026-03-03
在React和Vue中使用Mock.js模擬接口的實現(xiàn)方法
本文將介紹如何在React和Vue項目中使用Mock.js來模擬接口攔截請求,幫助開發(fā)者在不依賴后端的情況下高效地進行前端開發(fā),文中有詳細的代碼示例供大家參考,需要的朋友可以參考下2024-08-08
Vue2中compiler和runtime模式報錯template compiler is 
本文主要介紹了Vue2中compiler和runtime模式報錯template compiler is not available,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-07-07
Vue創(chuàng)建淺層響應(yīng)式數(shù)據(jù)的實例詳解
這篇文章主要介紹了Vue創(chuàng)建淺層響應(yīng)式數(shù)據(jù)的實例,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-11-11
vue-content-loader內(nèi)容加載器的使用方法
這篇文章主要介紹了vue-content-loader內(nèi)容加載器的使用方法,本文分步驟給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-08-08
Vue前端實現(xiàn)導(dǎo)出頁面為word的兩種方法
這篇文章主要介紹了Vue前端實現(xiàn)導(dǎo)出頁面為word的兩種方法,文中通過代碼示例和圖文介紹的非常詳細,對大家的學習或工作有一定的幫助,需要的朋友可以參考下2024-12-12

