实现文本 内容展开 / 收起

请添加图片描述

<template>
  <el-table :data="tableData" style="width: 100%" height="250">
    <el-table-column
      fixed
      prop="date"
      label="日期"
      width="150">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="120">
    </el-table-column>
    <el-table-column prop="message" label="描述" width="120" >
	    <template slot-scope="scope">
			<div>
			  <span :key="scope.row.isExpand+row.$index" class="multi-line" :style="{'-webkit-line-clamp': scope.row.isExpand}">
			    {{ scope.row.message }}
			  </span>
			  <el-button
			    v-if="scope.row.message.length>500"
			    type="text"
			    size="mini"
			    :icon="scope.row.icon"
			    @click="expand(scope.row)"
			  >{{ scope.row.isExpandContent }}</el-button>
			</div>
		</template>
	</el-table-column>
  </el-table>
</template>

<script>
export default {
  
   data() {
      return {
        tableData: [{
          date: '2016-05-03',
          name: '王小虎',
          isExpandContent: '展开',
          isExpand: 5,
          message: '超多文本超多文本超多文本',
        }, {
          date: '2016-05-02',
          name: '王小虎',
          isExpandContent: '展开',
          isExpand: 5,
          message: '超多文本超多文本超多文本',
        }]
      }
    },
  methods: {
  	expand (row) {
        if (row.isExpandContent === '展开'){
            this.$set(row,'isExpandContent','收起')
            this.$set(row,'isExpand','')
            this.$set(row,'icon','icon-arrow-up')
        } else {
            this.$set(row,'isExpandContent','展开')
            this.$set(row,'isExpand',5)
            this.$set(row,'icon','icon-arrow-right')
        }
    },
  }
}
</script>
<style lang="scss" scoped>
.multi-line{
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
</style>

可根据代码升级优化

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值