当前位置: 首页 > news >正文

vxe-table 单元格 Tooltip 内容过多时启用滚动条

在使用 vxe-table 时,单元格内容过长会触发 Tooltip 悬浮提示。但默认的 Tooltip 尺寸有限,当提示内容非常多(例如包含大量文字、自定义组件、列表等)时,会出现内容溢出、显示不全的问题。本文将介绍如何通过配置 tooltipConfig 及相关插槽,让 Tooltip 容器固定宽高并自动显示滚动条,从而优雅地展示所有内容。

参数说明

vxe-table 为表头(header)、单元格(body)、表尾(footer)分别提供了独立的 Tooltip 配置项:

配置属性 作用对象 常用字段
headerTooltipConfig 表头单元格(需开启 showHeaderOverflow) width, height, maxWidth, maxHeight
tooltipConfig 数据行单元格(需开启 showOverflow) width, height, maxWidth, maxHeight
footerTooltipConfig 表尾单元格(需开启 showFooterOverflow) width, height, maxWidth, maxHeight

当 Tooltip 内容超过 maxWidth 或 maxHeight 时,内部会自动出现滚动条。你也可以直接设置固定 width / height 强制指定容器尺寸。

代码

image

<template><div><vxe-grid v-bind="gridOptions"><!-- 自定义表头 Tooltip 内容 --><template #header-tooltip="{ column }"><div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div><div style="color: red;">自定义表头:{{ column.title }}</div></div></template><!-- 自定义单元格 Tooltip 内容 --><template #tooltip="{ row, column }"><div style="width: 800px;"><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link><div style="color: orange;">自定义:{{ row[column.field] }}</div><vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link></div></template><!-- 自定义表尾单元格 Tooltip 内容 --><template #footer-tooltip="{ row, column }"><div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div><div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div></div></template></vxe-grid></div>
</template><script setup>
import { reactive } from 'vue'const gridOptions = reactive({height: 300,showOverflow: true,showHeaderOverflow: true,showFooterOverflow: true,showFooter: true,// 表头 Tooltip 尺寸限制:最大宽200,最大高100,超出滚动headerTooltipConfig: {maxWidth: 200,maxHeight: 100},// 单元格 Tooltip 尺寸限制:最大宽400,最大高300tooltipConfig: {maxWidth: 400,maxHeight: 300},// 表尾 Tooltip 尺寸限制footerTooltipConfig: {maxWidth: 200,maxHeight: 100},columns: [{ field: 'seq', type: 'seq', width: 70 },{ field: 'name', title: '名称' },{ field: 'role', title: '角色' },{ field: 'date', title: '日期日期日期日期日期日期日期日期日期', width: 200 },{ field: 'rate', title: 'Rate' },{ field: 'address', title: '地址地址地址地址地址地址地址地址地址地址', width: 200 }],data: [{ name: 'Test1', role: '前端', date: '2020-02-14', rate: 5, address: 'address1' },{ name: 'Test2', role: '后端', date: '2020-02-22', rate: 2, address: 'address1' },{ name: 'Test3', role: '前端前端前端前端前端前端前端前端', date: '2020-01-01', rate: 0, address: '深圳市深圳市深圳市深圳市深圳市深圳市' },{ name: 'Test4', role: '设计师设计师设计师设计师设计师设计师设计师', date: '2020-02-23', rate: 1, address: '上海市上海市上海市上海市上海市上海市' },{ name: 'Test5', role: '前端', date: '2020-01-20', rate: 3, address: '广州市广州市广州市广州市广州市广州市广州市广州市广州市' }],footerData: [{ seq: '合计', date: '2020-02-23', rate: '123456789123456789123456789123456789' }]
})
</script>
  • tooltipConfig 仅对设置了 showOverflow 的列生效。对于不开启溢出提示的列,Tooltip 不会出现,也就无法控制滚动。
  • 如果自定义插槽内容本身已经具有滚动条(例如内部 div 设置了 overflow: auto),则表格的 maxHeight 仍会限制整个 Tooltip 容器,可能导致双重滚动条。建议统一使用表格配置控制,避免内嵌滚动。

https://vxetable.cn

http://www.jsqmd.com/news/808248/

相关文章:

  • 脉冲多普勒引信抗箔条干扰方法【附代码】
  • 操作系统怎么防护才安全?这份全方位防攻击策略,解决 90% 计算机被入侵的问题
  • 5分钟掌握KMS_VL_ALL_AIO:智能激活Windows与Office的完整指南
  • Faster-Whisper-GUI:免费高效的语音识别工具终极指南
  • 芯片设计效率革命:视频化支持如何攻克EDA工具使用难题
  • 2026年成都水刀配件厂家深度评测:超高压增压总成、水刀易损配件一站式采购与故障诊断完全指南 - 优质企业观察收录
  • 极简OpenAI API封装库:快速集成AI能力的轻量级解决方案
  • Taotoken用量看板如何帮助团队清晰管理大模型API成本
  • AI赋能制造业:构建智能培训系统,破解技能缺口难题
  • AI开发者实战指南:从工具全景到本地知识库搭建
  • Eclipse CDT开发C/C++项目时,头文件路径配置保姆级教程(解决Unresolved inclusion报错)
  • 河南生物科技公司哪家靠谱? - 中媒介
  • AI智能体配置安全:Config Guard如何防止Agent“自杀式”配置变更
  • Twake插件系统开发指南:从零开始构建自定义功能模块
  • 机器学习入门终极指南:简单线性回归完整实战教程(附Python代码示例)
  • 迭代算法误差弹性与能效优化技术解析
  • LiveQing接收大疆等无人机RTMP推流直播录像后-何如操作视频流转成GB28181作为下级向上级联到其他GB28181国标平台
  • 芯片人才危机破局:D.E.I.B.战略如何驱动创新与商业成功
  • 告别手动配置!用这个递归Makefile模板,自动处理多级目录C项目编译
  • 省级旗舰标准 安徽爱尔眼科医院全面提升眼科诊疗服务水平 - 安互工业信息
  • 支付宝立减金回收方法:如何选择回收平台 - 团团收购物卡回收
  • 2026 年辽阳汽车贴膜全流程深度攻略:从入门到避坑一站式百科 - 速递信息
  • DeepSeekMath 7B:重新定义数学推理的智能边界
  • WarcraftHelper:魔兽争霸III玩家的三大痛点解决方案
  • 别慌!手把手教你读懂Linux内核的‘临终遗言’(oops信息实战解析)
  • AI元人文体系的发生学与本体论——意义行为原生自感痕迹论(阐释与勘误)
  • 深圳宇亿再生资源回收:宝安区发电机注塑机回收推荐几家 - LYL仔仔
  • 工业移动化破局:从COM模块化思想到MIPI接口标准的工业移动平台构建
  • 山东养生培训哪家效果好? - 中媒介
  • 用SourceTree搞定Git冲突后,为什么我的提交历史变成了一团乱麻?