在tabel表格中超出隐藏内容并展示展开收起

直接上代码  进行组件封装

<template>
  <div>
    <div v-if="valueType==1" style="position: relative;">
      <div :class="{'tdboxs':true, 'tdboxx': type1  }" ref="tdbox" :style="{maxHeight: type1 ? '' : '-webkit-box'}">
        <div class="tds" ref="tds" v-html="value ? value : '-'">
        </div>
        <i 
          v-show="type && type1"
          @click="type1=!type1" 
          :style="{transform: type1 ? 'rotate(90deg)' : 'rotate(270deg)', transition:'.1s'}" 
          class="el-icon-d-arrow-right cursor showtype">
        </i>
      </div>
      <span :class="[type1 ? 'zk1' : 'zk2']" v-show="type &&!type1">
        <i 
          @click="type1=!type1" 
          :style="{transform: type1 ? 'rotate(180deg)' : 'rotate(270deg)', transition:'.1s'}" 
          class="el-icon-d-arrow-right cursor showtype">
        </i>
        </span>
    </div>
    <div v-else style="position: relative;">
      <div class="tdbox" ref="tdbox" :style="{display: type1 ? '' : '-webkit-box'}">
        <div class="tds" ref="tds" v-html="value ? value : '-'">
        </div>
        <i 
          v-show="type && type1"
          @click="type1=!type1" 
          :style="{transform: type1 ? 'rotate(90deg)' : 'rotate(270deg)', transition:'.1s'}" 
          class="el-icon-d-arrow-right cursor showtype">
        </i>
      </div>
      <span :class="[type1 ? 'zk1' : 'zk2']" v-show="type &&!type1">
        <i 
          @click="type1=!type1" 
          :style="{transform: type1 ? 'rotate(180deg)' : 'rotate(270deg)', transition:'.1s'}" 
          class="el-icon-d-arrow-right cursor showtype">
        </i>
        </span>
    </div>
  </div>
</template>

<script>
export default {
  props:["value",'valueType'],
  data () {
    return {
      type: false,
      type1: false,
    }
  },
  mounted () {
    this.$nextTick(() =>{
      if(this.value && this.valueType == 1){
        let tdbox = this.$refs.tdbox.offsetHeight ? this.$refs.tdbox.offsetHeight : 0
        let tds = this.$refs.tds.offsetHeight ? this.$refs.tds.offsetHeight : 0
        this.type = tds > tdbox ? true : false
      } else {
        let tdbox = this.$refs.tdbox.offsetHeight ? this.$refs.tdbox.offsetHeight : 0
        let tds = this.$refs.tds.offsetHeight ? this.$refs.tds.offsetHeight : 0
        this.type = tds >= tdbox ? true : false
      }
    });
  },
}
</script>

<style scoped lang="less">
  .tdbox{
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    .tds {
      height: 100%;
      display: inline;
    }
  }
  .tdboxs{
    max-height: 70px;
    overflow: hidden;
    .tds {
      height: 100%;
    }
  }
  .tdboxx{
    max-height: 100%;
    // overflow: hidden;
    .tds {
      height: 100%;
    }
  }
  .showtype {
    font-size: 16px;
    color: #006CE3;
  }
  .zk2 {
    display: inline-block;
    background: #fff;
    position: absolute;
    right: 0;
    bottom: 0;
  }
  .zk2::before  {
    content: '...';
    margin-right: 3px;
    animation: blink 1s infinite
  }
</style>

使用方法先进行引入注册为组件名为<tds></tds>  可接受value与valueType两种参数  如value值为inline文本类型可不传, 如果为html格式则为 '1'  可适当修改代码进行适配多行问题

<table class="table_two1" v-if="arr.length > 1">
                  <!-- <tbody > -->
                    <tr v-for="(item,index) in arr" :key="index">
                      <template v-if="index ==0">
                        <th v-for="(items,indexs) in item" :key="indexs" v-html="items ? items: ''"></th>
                      </template>
                      <template v-if="index>0">
                        <td v-for="(items,indexs) in item" :key="indexs" >
                          <tds :value="items"></tds>
                        </td>
                      </template>
                    </tr>
                  <!-- </tbody> -->
                </table>

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值