elementUI el-table实现鼠标悬浮某一行,在鼠标右侧展示提示信息
在Element UI的el-table
组件中,可以通过el-table
的cell-mouse-enter
和cell-mouse-leave
事件来实现鼠标悬浮行的提示信息。以下是一个简单的示例代码:
<template>
<el-table
:data="tableData"
style="width: 100%"
@cell-mouse-enter="handleMouseEnter"
@cell-mouse-leave="handleMouseLeave"
>
<el-table-column
prop="date"
label="日期"
width="180">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
width="180">
</el-table-column>
<el-table-column
prop="address"
label="地址"
show-overflow-tooltip>
</el-table-column>
</el-table>
<div v-if="tooltip.visible" :style="tooltip.style">
{{ tooltip.content }}
</div>
</template>
<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '李小虎',
address: '上海市普陀区金沙江路 1517 弄'
}],
tooltip: {
visible: false,
content: '',
style: {
position: 'absolute',
backgroundColor: 'lightblue',
padding: '5px',
borderRadius: '4px',
display: 'none'
}
}
};
},
methods: {
handleMouseEnter(row, column, cell, event) {
const tooltipWidth = 150; // 提示框宽度
const tooltipHeight = 50; // 提示框高度
const position = cell.getBoundingClientRect();
this.tooltip.content = `${column.property}: ${row[column.property]}`;
this.tooltip.style.top = `${position.top + position.height + window.scrollY}px`;
this.tooltip.style.left = `${position.left + position.width / 2 - tooltipWidth / 2}px`;
this.tooltip.style.display = 'block';
this.tooltip.visible = true;
},
handleMouseLeave(row, column, cell, event) {
this.tooltip.visibl
评论已关闭