el-table 原本的 cell-click
不能修改为捕获时触发,因此我们只能在自定义列中添加一层专门用于处理列的点击,并绑定.capture
保证它在,按钮之前执行。
<template>
<el-table :data="tableData" style="width: 100%" @cell-click="onCellClick">
<el-table-column align="right">
<template #default="scope">
<div @click.capture="cellClick(scope.row)">
<el-button size="small" @click="handleEdit(scope.$index, scope.row)">
Edit
</el-button>
</div>
</template>
</el-table-column>
</el-table>
</template>
<script lang="ts" setup>
interface User {
date: string
name: string
address: string
}
const handleEdit = (index: number, row: User) => {
console.log(index, row, 'handleEdit')
}
const tableData: User[] = [
{
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
},
]
const onCellClick = () => {
console.log('onCellClick');
}
const cellClick = (row:any) => {
console.log('cellClick', row);
}
</script>