Vue 使用 Element UI表格组件 实现文本超出长度显示省略号,鼠标移上悬浮展示全部内容

<template>  
    <el-table  
      :data="tableData"  
      style="width: 100%"  
    >  
      <el-table-column  
        prop="date"  
        label="日期"  
        width="180"
        :show-overflow-tooltip="true"
      ></el-table-column>  
      <el-table-column  
        prop="name"  
        label="姓名"  
        width="180"
        :show-overflow-tooltip="true"
      ></el-table-column>  
      <el-table-column  
        prop="address"  
        label="地址"  
        width="180"  
        :show-overflow-tooltip="true"  
      ></el-table-column>  
    </el-table>  
  </template>  
    
  <script>  
  export default {  
    data() {  
      return {  
        tableData: [{  
          date: '2016-05-03',  
          name: '王小虎',  
          address: '上海市普陀区金沙江路 1518 弄'  
        }, {  
          date: '2016-05-02',  
          name: '王大虎',  
          address: '上海市普陀区金沙江路 1517 弄'  
        }, {  
          date: '2016-05-04',  
          name: '王小明',  
          address: '上海市普陀区金沙江路 1519 弄'  
        }, {  
          date: '2016-05-01',  
          name: '王小红',  
          address: '上海市普陀区金沙江路 1520 弄'  
        }]  
      }  
    }  
  }  
  </script>

 只需在表格添加:show-overflow-tooltip="true"属性即可

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过 CSS 中的 `text-overflow` 属性和 Vue 中的条件渲染来实现。 首先,设置盒子的宽度和高度,并使用 `overflow: hidden` 属性隐藏超出部分。然后,使用 `text-overflow: ellipsis` 属性让超出部分以省略号的形式显示。 接着,使用 Vue 的条件渲染,在内容未超出时不渲染悬浮框。在内容超出时,使用 `@mouseover` 事件触发悬浮框的显示,并将完整内容传递到悬浮组件展示。 下面是一个简单的示例代码: ```vue <template> <div class="box" :class="{ 'over': isOver }" @mouseover="showPopup" @mouseleave="hidePopup"> {{ content }} <popup v-if="isOver" :content="content" /> </div> </template> <script> import Popup from './Popup.vue'; export default { components: { Popup, }, data() { return { content: '这是一段超出部分将要省略的内容', isOver: false, }; }, methods: { showPopup() { this.isOver = true; }, hidePopup() { this.isOver = false; }, }, }; </script> <style> .box { width: 200px; height: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .box.over { cursor: pointer; } .popup { position: absolute; top: 60px; left: 0; padding: 10px; background-color: #fff; border: 1px solid #ccc; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); } </style> ``` 在上面的示例代码中,`Popup` 组件是一个展示完整内容的悬浮组件。在 `box` 盒子组件中,使用 `:class` 绑定了一个 `over` 类,表示内容是否超出。在 `@mouseover` 事件中,将 `isOver` 设为 `true`,触发悬浮框的显示。在 `@mouseleave` 事件中,将 `isOver` 设为 `false`,触发悬浮框的隐藏。在 `popup` 组件中,将 `content` 作为属性传递进去,用于展示完整内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值