vue+element-ui el-table表格(含表头)内容溢出省略,鼠标悬浮提示

摘要:
divclass=“test”>templateslot scope=“scope”slot=“header”>div@mouseover=“鼠标悬停('refName'+scope.$index)”>content=“item.label”placement=“top”>ref=“'refName'+scope.$index”>
第一种:
参考:https://my.oschina.net/u/3455362/blog/4674804

<template>
  <div class="test">
        <el-table :data="gridData" border stripe style=" 100%">
          <template v-for="item in gridDataHeader">
            <el-table-column :prop="item.key" :key="item.key" :label="item.label" :  show-overflow-tooltip>
              <template slot-scope="scope" slot="header">
                <div @mouseover="onMouseOver('refName' + scope.$index)">
                  <el-tooltip :disabled="isShowTooltip" :content="item.label" placement="top">
                    <div class="long_title">
                      <span :ref="'refName' + scope.$index">{{item.label}}</span>
                    </div>
                  </el-tooltip>
                </div>
              </template>
            </el-table-column>
          </template>
        </el-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      gridDataHeader: [
        {key:'date',label:'日期afdsasfasdfasfdasasfasfasdfasdfasdfadsfdfasdf','100',aling:'center'},
        {key:'name',label:'姓名','200',aling:'center'},
        {key:'address',label:'地址','100',aling:'center'}
      ],
      gridData: [
        {
          date:
            "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄afsafasfergtujyjhgngfhddfghdgfhgfdh",
        },
      ],
      isShowTooltip: false,
    };
  },
  methods: {
    onMouseOver(refName) {
      let parentWidth = this.$refs[refName][0].parentNode.offsetWidth;
      let contentWidth = this.$refs[refName][0].offsetWidth;
      // 判断是否开启tooltip功能
      if (contentWidth > parentWidth) {
        this.isShowTooltip = false;
      } else {
        this.isShowTooltip = true;
      }
    },
  },
};
</script>
<style>
.long_title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>

  第二种:el-table中render-header

<template>
  <div class="TableHeaderTest">
    <el-table
      size="small"
      border
      v-loading="loading"
      :data="tableData"
       
    >
      <el-table-column prop="city_name" label="城市"> </el-table-column>
      <el-table-column prop="maxprice" :render-header="renderHeader">
        <template slot-scope="scope">
          <span
            ><span class="skucost-pruice">¥</span
            ><span class="skucost-pruice">{{ scope.row.maxprice }}</span></span
          >
        </template>
      </el-table-column>
      <el-table-column prop="company_name" label="机构名称"> </el-table-column>
      <el-table-column prop="area_name" label="区域"> </el-table-column>
      <el-table-column prop="price" label="价格">
        <template slot-scope="scope">
          <span
            ><span class="skucost-pruice">¥</span
            ><span class="skucost-pruice">{{ scope.row.price }}</span></span
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  name: "TableHeaderTest",
  data() {
    return {
      loading: false,
      tableData: [
        {
          city_name: "fafa",
          maxprice: "123",
          company_name: "sfdgsfdgfsd",
          area_name: "hgfhdgf",
          price: "123",
        },
      ],
    };
  },
  methods: {
    //自定义表头
    renderHeader(h) {
      return h("span", {}, [
        // h("span",{class: "headerTest",},"价格"),
        h(
          "el-popover",
          {
            props: {
              placement: "top",
               "200",
              trigger: "hover",
              content: "城市价格为该城市所有加盟商价格的最高价",
            },
          },
        //   [h("", { slot: "reference", class: "el-icon-question" }, "")]
        [h("span",{slot: "reference",class: "headerTest",},"价格就分手;收款方使肌肤的哈萨克复读机啊阿凡达阿斯顿发的说法放大石头人gas发送到发")]
        ),
      ]);
    },
  },
};
</script>
<style>
.headerTest {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
注:el-tooltip写法
renderHeader(h,{column}){
  console.log(column);
  if(column.label){//表头名称
    reutrn (
      <el-tooltip errect="dark" content={column.label} placement="top">//鼠标悬浮提示
        <span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">{column.label}</span>//表头名称
      </el-tooltip>
    )
  }
}

  

免责声明:文章转载自《vue+element-ui el-table表格(含表头)内容溢出省略,鼠标悬浮提示》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Sqlite—索引介绍expect安装去测试下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Mybatis标签及使用1

Mysatis的特点是以SQL语句为核心的不完全的ORM(关系型映射)框架 parameterType:在SQL映射文件中指定输入参数类型的,基本类型(int、float)、包装数据类型(String、Integer)以及用户自己编写的JavaBean封装类 resultType:指定数据库返回信息对应的Java的数据类型。在加载SQL配置,并绑定指定输入...

提高iOS开发效率的第三方框架等--不断更新中。。。

1. Mantle Mantle 让我们能简化 Cocoa 和 Cocoa Touch 应用的 model 层。简单点说,程序中经常要进行网络请求,请求到得一般是 json 字符串,我们一般会建一个 Model 类来存放这些数据。这就要求我们编写一系列的序列化代码,来把 json 转换为 Model 。这很费时间,容易错,不容易修改。 Mantle 很好...

iOS UIBezierPath简单实用

 转载请注明出处!!! 1.介绍       UIBezierPath这个类在UIKit中, 是Core Graphics框架关于path的一个封装,使用此类可以定义简单的形状,比如我们常用到,矩形,圆形,椭圆,弧,或者不规则的多边形      每一个直线段或者曲线段的结束的地方是下一个的开始的地方。每一个连接的直线或者曲线段的集合成为subpath。一...

机器学习技法 --- 融合模型

1、主要内容   在已经使用某个模型的情况下,如何将这些模型进行融合使得模型更好的预测,这种技术就是融合模型技术。 2、融合模型的引入   你要买股票,有T个朋友做参考你听谁的?买还是不买?      你可以采取的措施: 选择最有价值的朋友的推荐---对应到机器学习就是一个模型的选择,就是验证(validation)选择性能最好的那个模型 或者认为他们的...

iOS:iOS开发中用户密码保存位置

原文来自简书:http://www.jianshu.com/p/4af3b8179136/comments/1294203 如果要实现自动登录,不必每次打开应用都去登录,我们势必要把密码保存到本地。一般我们的操作是:每次打开应用后,如果存在密码,直接进入界面,然后再进行后台密码验证。如果没网络,我们可以跳过验证;如果有网络,我们可以后台去验证帐号密码的正确...

MySQL之表字段的处理

一、删除、添加表字段删除表字段: mysql> ALTER TABLE testalter_tbl DROP i; 注意:若表中只剩余一个字段时,是无法使用DROP来进行删除的。 添加字段: ALTER TABLE testalter_tbl ADD i INT; 注意:添加字段时必须指定字段的数据类型。且添加的字段默认添加到表字段的末尾处。 若要...