element-ui里的el-table是怎么实现超出内容省略并加tooltip提示的?

效果图
在这里插入图片描述
效果描述:
只有超出10个字的标题才会显示el-tooltip,没有超出的不会显示
思路:表格中的数据超出10个字显示隐藏,用hover效果显示el-tooltip并显示全部的文字
代码:

     <el-table-column label="标题" width="180">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.title"
              placement="bottom"
              popper-class="tips"
            >
              <span v-if="scope.row.title.length >= 10">{
   
   {
                scope.row.title
              }}</span>
            </el-tooltip>
            <span v-if="scope.row.title.length < 10">{
   
   {
              scope.row.title
            }}</span>
          </template>
     </el-table-column>
/deep/.el-table td {
    border-bottom: 1px solid #2E2C3D;
    background: #242133;

    .cell span {
        display: block;
        width: 10em;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
}

**提示:**把cell样式里面的em单位换成width也可以实现,具体看需求

猜你喜欢

转载自blog.csdn.net/lqlq54321/article/details/110818900